From 972a6d3e4d3b684fbadeb5cd046a8634ec24eb8c Mon Sep 17 00:00:00 2001 From: Arturs Artamonovs Date: Mon, 3 Feb 2025 22:31:45 +0000 Subject: iqconvert: converts from u8 to f32 without issues --- Utils/Double+truncate.swift | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Utils/Double+truncate.swift (limited to 'Utils/Double+truncate.swift') 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) + } +} -- cgit v1.2.3