diff options
author | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2025-02-03 22:31:45 +0000 |
---|---|---|
committer | Arturs Artamonovs <arturs.artamonovs@protonmail.com> | 2025-02-03 22:31:45 +0000 |
commit | 972a6d3e4d3b684fbadeb5cd046a8634ec24eb8c (patch) | |
tree | e96c4ce2d649558cc0b7b452d7a64fbe980b65c0 /Utils/Double+truncate.swift | |
parent | 1e096e55ca30dc80c3faa8d1ea36de13bc90cc6a (diff) | |
download | PrySDR-972a6d3e4d3b684fbadeb5cd046a8634ec24eb8c.tar.gz PrySDR-972a6d3e4d3b684fbadeb5cd046a8634ec24eb8c.zip |
iqconvert: converts from u8 to f32 without issuesmain
Diffstat (limited to 'Utils/Double+truncate.swift')
-rw-r--r-- | Utils/Double+truncate.swift | 26 |
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) + } +} |