summaryrefslogtreecommitdiff
path: root/Utils/Double+truncate.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Utils/Double+truncate.swift')
-rw-r--r--Utils/Double+truncate.swift26
1 files changed, 26 insertions, 0 deletions
diff --git a/Utils/Double+truncate.swift b/Utils/Double+truncate.swift
new file mode 100644
index 0000000..b86d51d
--- /dev/null
+++ b/Utils/Double+truncate.swift
@@ -0,0 +1,26 @@
+//
+// Double+truncate.swift
+// PrySDR
+//
+// Created by Jacky Jack on 23/01/2025.
+//
+
+import Foundation
+
+extension Double {
+ func truncate(places : Int)-> Double {
+ return Double(floor(Foundation.pow(10.0, Double(places)) * self)/Foundation.pow(10.0, Double(places)))
+ }
+}
+
+extension Float32 {
+ func truncate(places : Int)-> Float32 {
+ return Float32(floor(Foundation.pow(10.0, Float32(places)) * self)/Foundation.pow(10.0, Float32(places)))
+ }
+}
+
+extension Float32 {
+ var bytes: [UInt8] {
+ withUnsafeBytes(of: self, Array.init)
+ }
+}