OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // QuicBandwidth represents a bandwidth, stored in bits per second resolution. | 5 // QuicBandwidth represents a bandwidth, stored in bits per second resolution. |
6 | 6 |
7 #ifndef NET_QUIC_QUIC_BANDWIDTH_H_ | 7 #ifndef NET_QUIC_QUIC_BANDWIDTH_H_ |
8 #define NET_QUIC_QUIC_BANDWIDTH_H_ | 8 #define NET_QUIC_QUIC_BANDWIDTH_H_ |
9 | 9 |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 | 11 |
| 12 #include <cmath> |
12 #include <ostream> | 13 #include <ostream> |
13 | 14 |
14 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
15 #include "net/quic/core/quic_time.h" | 16 #include "net/quic/core/quic_time.h" |
16 | 17 |
17 namespace net { | 18 namespace net { |
18 | 19 |
19 typedef uint64_t QuicByteCount; | 20 typedef uint64_t QuicByteCount; |
20 typedef uint64_t QuicPacketCount; | 21 typedef uint64_t QuicPacketCount; |
21 | 22 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 } | 92 } |
92 | 93 |
93 // Non-member arithmetic operators for QuicBandwidth. | 94 // Non-member arithmetic operators for QuicBandwidth. |
94 inline QuicBandwidth operator+(QuicBandwidth lhs, QuicBandwidth rhs) { | 95 inline QuicBandwidth operator+(QuicBandwidth lhs, QuicBandwidth rhs) { |
95 return QuicBandwidth(lhs.bits_per_second_ + rhs.bits_per_second_); | 96 return QuicBandwidth(lhs.bits_per_second_ + rhs.bits_per_second_); |
96 } | 97 } |
97 inline QuicBandwidth operator-(QuicBandwidth lhs, QuicBandwidth rhs) { | 98 inline QuicBandwidth operator-(QuicBandwidth lhs, QuicBandwidth rhs) { |
98 return QuicBandwidth(lhs.bits_per_second_ - rhs.bits_per_second_); | 99 return QuicBandwidth(lhs.bits_per_second_ - rhs.bits_per_second_); |
99 } | 100 } |
100 inline QuicBandwidth operator*(QuicBandwidth lhs, float rhs) { | 101 inline QuicBandwidth operator*(QuicBandwidth lhs, float rhs) { |
101 return QuicBandwidth(static_cast<int64_t>(lhs.bits_per_second_ * rhs)); | 102 return QuicBandwidth( |
| 103 static_cast<int64_t>(std::llround(lhs.bits_per_second_ * rhs))); |
102 } | 104 } |
103 inline QuicBandwidth operator*(float lhs, QuicBandwidth rhs) { | 105 inline QuicBandwidth operator*(float lhs, QuicBandwidth rhs) { |
104 return rhs * lhs; | 106 return rhs * lhs; |
105 } | 107 } |
106 | 108 |
107 // Override stream output operator for gtest. | 109 // Override stream output operator for gtest. |
108 inline std::ostream& operator<<(std::ostream& output, | 110 inline std::ostream& operator<<(std::ostream& output, |
109 const QuicBandwidth bandwidth) { | 111 const QuicBandwidth bandwidth) { |
110 output << bandwidth.ToDebugValue(); | 112 output << bandwidth.ToDebugValue(); |
111 return output; | 113 return output; |
112 } | 114 } |
113 | 115 |
114 } // namespace net | 116 } // namespace net |
115 #endif // NET_QUIC_QUIC_BANDWIDTH_H_ | 117 #endif // NET_QUIC_QUIC_BANDWIDTH_H_ |
OLD | NEW |