Skip to content

Commit

Permalink
Fix bug in strUt.fmtUncertain family of procs where (3.99,2.08) would
Browse files Browse the repository at this point in the history
round to (4.00,0.21); 10X too small errors are v.bad for pseudo t-tests.
Update test suite to cover this case & to also test/show 1-sig digit.
Also update release notes.
  • Loading branch information
c-blake committed Feb 13, 2024
1 parent e58f95c commit 53c7916
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 3 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ Version: 1.7.0
Existing TOML users likely need to simplify just 1 file in a user config
(although running under `NO_COLOR=1` is another option).

- Fix bug in the strUt.fmtUncertain family of procs where (3.99, 2.08) would
round to (4.00, 0.21); I.e. 10X too small error; v.bad for pseudo t-tests.

Version: 1.6.18
---------------
- Add cligen/mslice.within to test if one slice entirely brackets another
Expand Down
10 changes: 6 additions & 4 deletions cligen/strUt.nim
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ proc ecvtM(s: var string; x: float; i, e: var int; bumped: var bool; p=17;
n0R = p - 18
p = 18 # 64 bits==19 decs but sgn & round trick
let frac = uint64((scl - dig.float)*pow10[p] + 0.5)
if frac.float >= pow10[p]: # 9.99 with prec 1 rounding up
inc dig; bumped = true
if frac.float >= pow10[p]: # D.99 with prec 1 rounding up
bumped = dig==9; inc dig # but `bumped` tracks only po10 change
elif frac != 0: # post decimal digits to convert
i0 = uint64toDecimal(decs, frac)
nDec = 24 - i0
Expand Down Expand Up @@ -612,10 +612,11 @@ when isMainModule:
let fmt = nmFmt[1]
if k != 0: echo ""
echo nmFmt[0]
for j, p in [2, 3]: # This all works with/without dragonbox
for j, p in [1, 2, 3]: # This all works with/without dragonbox
if j != 0: echo ""; echo ""
for i, sd in [ 1.23456e-6, 9.9996543, 1234.56, 99996.543 ]:
if i != 0: echo ""
if i != 0: echo "" # Show raw input & rounded output
else: echo "p=",p
echo "+1.2345678e-5 ", sd, "\t\t", fmt(+1.2345678e-5, sd, p)
echo "+12.34567890 ", sd, "\t\t", fmt(+12.34567890 , sd, p)
echo "+123.4567890 ", sd, "\t\t", fmt(+123.4567890 , sd, p)
Expand All @@ -626,6 +627,7 @@ when isMainModule:
echo "-123.4567890 ", sd, "\t\t", fmt(-123.4567890 , sd, p)
echo "-9.432101234 ", sd, "\t\t", fmt(-9.432101234 , sd, p)
echo "-9.987654321 ", sd, "\t\t", fmt(-9.987654321 , sd, p)
echo "-39.99 ", sd, "\t\t", fmt(-39.99 , sd, p)
echo "\nSPECIALS FP VALUES:"
let minf = -1.0/0.0
let pinf = +1.0/0.0
Expand Down

0 comments on commit 53c7916

Please sign in to comment.