Просмотр исходного кода

Make double rounding for Decimal systematic

Sam King 5 месяцев назад
Родитель
Сommit
7d0f2585bd

+ 2 - 1
Trio/Sources/APS/OpenAPSSwift/Extensions/Decimal+rounding.swift

@@ -31,7 +31,8 @@ extension Decimal {
     }
 
     func jsRounded() -> Decimal {
-        jsRounded(scale: 0)
+        // double rounding to help with imprecision in calculations
+        jsRounded(scale: 6).jsRounded(scale: 0)
     }
 
     func clamp(lowerBound: Decimal, upperBound: Decimal) -> Decimal {

+ 1 - 4
Trio/Sources/APS/OpenAPSSwift/Forecasts/ForecastGenerator.swift

@@ -313,10 +313,7 @@ enum ForecastGenerator {
         } else if ztResult.minGuardGlucose > uamResult.minForecastGlucose {
             minZTUAMForecastGlucose = (uamResult.minForecastGlucose + ztResult.minGuardGlucose) / 2
         }
-        // Note: We found at least one case where decmial weren't able
-        // to handle the precision of a calculation, so we'll do the
-        // double rounding trick we do in JS sometimes
-        minZTUAMForecastGlucose = minZTUAMForecastGlucose.jsRounded(scale: 6).jsRounded()
+        minZTUAMForecastGlucose = minZTUAMForecastGlucose.jsRounded()
 
         // 2. avgForecastGlucose blending (like avgPredBG)
         let avgerageForecastGlucose: Decimal

+ 1 - 1
TrioTests/OpenAPSSwiftTests/DetermineBasalJsonTests.swift

@@ -103,7 +103,7 @@ import Testing
         // this test is meant for one-off analysis so it's ok to hard code
         // a file, just make sure to _not_ check in updates to this to
         // avoid polluting our change logs
-        let algorithmComparison = try await HttpFiles.downloadFile(at: "/files/240ecbe9-5903-46ca-a4af-a4a0aebbf8a0.4.json")
+        let algorithmComparison = try await HttpFiles.downloadFile(at: "/files/dc9ebaee-a256-435a-8a2a-dcd2abbd9462.0.json")
         let determineBasalInput = algorithmComparison.determineBasalInput!
 
         let encoder = JSONCoding.encoder