Sho SHIMIZU
Committed by Thomas Vachuska

Avoid potential round-off error caused by floating point

Change-Id: If1a6266c7a0951441de3fe444663a109bb819056
...@@ -21,11 +21,11 @@ import org.onlab.util.Frequency; ...@@ -21,11 +21,11 @@ import org.onlab.util.Frequency;
21 * Represents interval frequency between two neighboring wavelengths. 21 * Represents interval frequency between two neighboring wavelengths.
22 */ 22 */
23 public enum ChannelSpacing { 23 public enum ChannelSpacing {
24 - CHL_100GHZ(100), // 100 GHz 24 + CHL_100GHZ(100_000), // 100 GHz
25 - CHL_50GHZ(50), // 50 GHz 25 + CHL_50GHZ(50_000), // 50 GHz
26 - CHL_25GHZ(25), // 25 GHz 26 + CHL_25GHZ(25_000), // 25 GHz
27 - CHL_12P5GHZ(12.5), // 12.5 GHz 27 + CHL_12P5GHZ(12_500), // 12.5 GHz
28 - CHL_6P25GHZ(6.25); // 6.25 GHz 28 + CHL_6P25GHZ(6_250); // 6.25 GHz
29 29
30 private final Frequency frequency; 30 private final Frequency frequency;
31 31
...@@ -34,8 +34,8 @@ public enum ChannelSpacing { ...@@ -34,8 +34,8 @@ public enum ChannelSpacing {
34 * 34 *
35 * @param value interval of neighboring wavelengths in GHz. 35 * @param value interval of neighboring wavelengths in GHz.
36 */ 36 */
37 - ChannelSpacing(double value) { 37 + ChannelSpacing(long value) {
38 - this.frequency = Frequency.ofGHz(value); 38 + this.frequency = Frequency.ofMHz(value);
39 } 39 }
40 40
41 public Frequency frequency() { 41 public Frequency frequency() {
......
...@@ -124,7 +124,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr ...@@ -124,7 +124,7 @@ public class OpenFlowDeviceProvider extends AbstractProvider implements DevicePr
124 private static final long KBPS = 1_000; 124 private static final long KBPS = 1_000;
125 private static final long MBPS = 1_000 * 1_000; 125 private static final long MBPS = 1_000 * 1_000;
126 private static final Frequency FREQ100 = Frequency.ofGHz(100); 126 private static final Frequency FREQ100 = Frequency.ofGHz(100);
127 - private static final Frequency FREQ4_4 = Frequency.ofTHz(4.4); 127 + private static final Frequency FREQ4_4 = Frequency.ofGHz(4_400);
128 128
129 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 129 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
130 protected DeviceProviderRegistry providerRegistry; 130 protected DeviceProviderRegistry providerRegistry;
......
...@@ -72,6 +72,16 @@ public final class Frequency implements RichComparable<Frequency> { ...@@ -72,6 +72,16 @@ public final class Frequency implements RichComparable<Frequency> {
72 * @param value frequency in KHz 72 * @param value frequency in KHz
73 * @return instance representing the given frequency 73 * @return instance representing the given frequency
74 */ 74 */
75 + public static Frequency ofKHz(long value) {
76 + return new Frequency(value * KHZ);
77 + }
78 +
79 + /**
80 + * Returns an instance representing the specified value in KHz.
81 + *
82 + * @param value frequency in KHz
83 + * @return instance representing the given frequency
84 + */
75 public static Frequency ofKHz(double value) { 85 public static Frequency ofKHz(double value) {
76 return new Frequency((long) (value * KHZ)); 86 return new Frequency((long) (value * KHZ));
77 } 87 }
...@@ -82,6 +92,16 @@ public final class Frequency implements RichComparable<Frequency> { ...@@ -82,6 +92,16 @@ public final class Frequency implements RichComparable<Frequency> {
82 * @param value frequency in MHz 92 * @param value frequency in MHz
83 * @return instance representing the given frequency 93 * @return instance representing the given frequency
84 */ 94 */
95 + public static Frequency ofMHz(long value) {
96 + return new Frequency(value * MHZ);
97 + }
98 +
99 + /**
100 + * Returns an instance representing the specified value in MHz.
101 + *
102 + * @param value frequency in MHz
103 + * @return instance representing the given frequency
104 + */
85 public static Frequency ofMHz(double value) { 105 public static Frequency ofMHz(double value) {
86 return new Frequency((long) (value * MHZ)); 106 return new Frequency((long) (value * MHZ));
87 } 107 }
...@@ -92,6 +112,16 @@ public final class Frequency implements RichComparable<Frequency> { ...@@ -92,6 +112,16 @@ public final class Frequency implements RichComparable<Frequency> {
92 * @param value frequency in GHz 112 * @param value frequency in GHz
93 * @return instance representing the given frequency 113 * @return instance representing the given frequency
94 */ 114 */
115 + public static Frequency ofGHz(long value) {
116 + return new Frequency(value * GHZ);
117 + }
118 +
119 + /**
120 + * Returns an instance representing the specified value in GHz.
121 + *
122 + * @param value frequency in GHz
123 + * @return instance representing the given frequency
124 + */
95 public static Frequency ofGHz(double value) { 125 public static Frequency ofGHz(double value) {
96 return new Frequency((long) (value * GHZ)); 126 return new Frequency((long) (value * GHZ));
97 } 127 }
...@@ -102,6 +132,16 @@ public final class Frequency implements RichComparable<Frequency> { ...@@ -102,6 +132,16 @@ public final class Frequency implements RichComparable<Frequency> {
102 * @param value frequency in THz 132 * @param value frequency in THz
103 * @return instance representing the given frequency 133 * @return instance representing the given frequency
104 */ 134 */
135 + public static Frequency ofTHz(long value) {
136 + return new Frequency(value * THZ);
137 + }
138 +
139 + /**
140 + * Returns an instance representing the specified value in THz.
141 + *
142 + * @param value frequency in THz
143 + * @return instance representing the given frequency
144 + */
105 public static Frequency ofTHz(double value) { 145 public static Frequency ofTHz(double value) {
106 return new Frequency((long) (value * THZ)); 146 return new Frequency((long) (value * THZ));
107 } 147 }
......
...@@ -24,31 +24,31 @@ package org.onlab.util; ...@@ -24,31 +24,31 @@ package org.onlab.util;
24 public final class Spectrum { 24 public final class Spectrum {
25 25
26 // Center frequency 26 // Center frequency
27 - public static final Frequency CENTER_FREQUENCY = Frequency.ofTHz(193.1); 27 + public static final Frequency CENTER_FREQUENCY = Frequency.ofGHz(193_100);
28 28
29 // O band (original): 1260 to 1360 nm 29 // O band (original): 1260 to 1360 nm
30 - public static final Frequency O_BAND_MIN = Frequency.ofTHz(220.436); 30 + public static final Frequency O_BAND_MIN = Frequency.ofGHz(220_436);
31 - public static final Frequency O_BAND_MAX = Frequency.ofTHz(237.931); 31 + public static final Frequency O_BAND_MAX = Frequency.ofGHz(237_931);
32 32
33 // E band (extended): 1360 to 1460 nm 33 // E band (extended): 1360 to 1460 nm
34 - public static final Frequency E_BAND_MIN = Frequency.ofTHz(205.337); 34 + public static final Frequency E_BAND_MIN = Frequency.ofGHz(205_337);
35 - public static final Frequency E_BAND_MAX = Frequency.ofTHz(220.436); 35 + public static final Frequency E_BAND_MAX = Frequency.ofGHz(220_436);
36 36
37 // S band (short wavelength): 1460 to 1530 nm 37 // S band (short wavelength): 1460 to 1530 nm
38 - public static final Frequency S_BAND_MIN = Frequency.ofTHz(195.943); 38 + public static final Frequency S_BAND_MIN = Frequency.ofGHz(195_943);
39 - public static final Frequency S_BAND_MAX = Frequency.ofTHz(205.337); 39 + public static final Frequency S_BAND_MAX = Frequency.ofGHz(205_337);
40 40
41 // C band (conventional): 1530 to 1565 nm 41 // C band (conventional): 1530 to 1565 nm
42 - public static final Frequency C_BAND_MIN = Frequency.ofTHz(191.561); 42 + public static final Frequency C_BAND_MIN = Frequency.ofGHz(191_561);
43 - public static final Frequency C_BAND_MAX = Frequency.ofTHz(195.943); 43 + public static final Frequency C_BAND_MAX = Frequency.ofGHz(195_943);
44 44
45 // L band (long wavelength): 1565 to 1625 nm 45 // L band (long wavelength): 1565 to 1625 nm
46 - public static final Frequency L_BAND_MIN = Frequency.ofTHz(184.488); 46 + public static final Frequency L_BAND_MIN = Frequency.ofGHz(184_488);
47 - public static final Frequency L_BAND_MAX = Frequency.ofTHz(191.561); 47 + public static final Frequency L_BAND_MAX = Frequency.ofGHz(191_561);
48 48
49 // U band (ultra-long wavelength): 1625 to 1675 nm 49 // U band (ultra-long wavelength): 1625 to 1675 nm
50 - public static final Frequency U_BAND_MIN = Frequency.ofTHz(178.981); 50 + public static final Frequency U_BAND_MIN = Frequency.ofGHz(178_981);
51 - public static final Frequency U_BAND_MAX = Frequency.ofTHz(184.488); 51 + public static final Frequency U_BAND_MAX = Frequency.ofGHz(184_488);
52 52
53 private Spectrum() { 53 private Spectrum() {
54 } 54 }
......
...@@ -102,7 +102,7 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider { ...@@ -102,7 +102,7 @@ class ConfigProvider implements DeviceProvider, LinkProvider, HostProvider {
102 private static final String UNKNOWN = "unknown"; 102 private static final String UNKNOWN = "unknown";
103 103
104 // C-band has 4.4 THz (4,400 GHz) total bandwidth 104 // C-band has 4.4 THz (4,400 GHz) total bandwidth
105 - private static final Frequency TOTAL = Frequency.ofTHz(4.4); 105 + private static final Frequency TOTAL = Frequency.ofGHz(4_400);
106 106
107 private CountDownLatch deviceLatch; 107 private CountDownLatch deviceLatch;
108 108
......