Avoid potential round-off error caused by floating point
Change-Id: If1a6266c7a0951441de3fe444663a109bb819056
diff --git a/utils/misc/src/main/java/org/onlab/util/Frequency.java b/utils/misc/src/main/java/org/onlab/util/Frequency.java
index 1ef7113..49eebcb 100644
--- a/utils/misc/src/main/java/org/onlab/util/Frequency.java
+++ b/utils/misc/src/main/java/org/onlab/util/Frequency.java
@@ -72,6 +72,16 @@
* @param value frequency in KHz
* @return instance representing the given frequency
*/
+ public static Frequency ofKHz(long value) {
+ return new Frequency(value * KHZ);
+ }
+
+ /**
+ * Returns an instance representing the specified value in KHz.
+ *
+ * @param value frequency in KHz
+ * @return instance representing the given frequency
+ */
public static Frequency ofKHz(double value) {
return new Frequency((long) (value * KHZ));
}
@@ -82,6 +92,16 @@
* @param value frequency in MHz
* @return instance representing the given frequency
*/
+ public static Frequency ofMHz(long value) {
+ return new Frequency(value * MHZ);
+ }
+
+ /**
+ * Returns an instance representing the specified value in MHz.
+ *
+ * @param value frequency in MHz
+ * @return instance representing the given frequency
+ */
public static Frequency ofMHz(double value) {
return new Frequency((long) (value * MHZ));
}
@@ -92,6 +112,16 @@
* @param value frequency in GHz
* @return instance representing the given frequency
*/
+ public static Frequency ofGHz(long value) {
+ return new Frequency(value * GHZ);
+ }
+
+ /**
+ * Returns an instance representing the specified value in GHz.
+ *
+ * @param value frequency in GHz
+ * @return instance representing the given frequency
+ */
public static Frequency ofGHz(double value) {
return new Frequency((long) (value * GHZ));
}
@@ -102,6 +132,16 @@
* @param value frequency in THz
* @return instance representing the given frequency
*/
+ public static Frequency ofTHz(long value) {
+ return new Frequency(value * THZ);
+ }
+
+ /**
+ * Returns an instance representing the specified value in THz.
+ *
+ * @param value frequency in THz
+ * @return instance representing the given frequency
+ */
public static Frequency ofTHz(double value) {
return new Frequency((long) (value * THZ));
}