dankamongmen / panelreels

high-level objects built atop ncurses
https://nick-black.com/dankwiki/index.php/Outcurses
Apache License 2.0
8 stars 1 forks source link

Honor rounding mode in prefix() output #15

Closed dankamongmen closed 4 years ago

dankamongmen commented 5 years ago

I've added a new test, PowerOfTwoAsTen, which runs powers of two against a mult of 1000 in prefix(). I test against %.2g output. This has demonstrated that we always truncate output rather than rounding, which I don't think is desirable. Go ahead and round to nearest number instead.

1
1.00 == 1.00
2
2.00 == 2.00
4
4.00 == 4.00
8
8.00 == 8.00
16
16.00 == 16.00
32
32.00 == 32.00
64
64.00 == 64.00
128
128.00 == 128.00
256
256.00 == 256.00
512
512.00 == 512.00
1.024
1.02K == 1.02K
2.048
2.05K == 2.04K
/home/dank/src/dankamongmen/outcurses/tests/prefix.cpp:155: Failure
Expected equality of these values:
  gold
    Which is: "2.05K"
  buf
    Which is: "2.04K"
4.096
4.10K == 4.09K
/home/dank/src/dankamongmen/outcurses/tests/prefix.cpp:155: Failure
Expected equality of these values:
  gold
    Which is: "4.10K"
  buf
    Which is: "4.09K"
8.192
8.19K == 8.19K
16.384
16.38K == 16.38K
32.768
32.77K == 32.76K
/home/dank/src/dankamongmen/outcurses/tests/prefix.cpp:155: Failure
Expected equality of these values:
  gold
    Which is: "32.77K"
  buf
    Which is: "32.76K"
dankamongmen commented 5 years ago

If we really want to do this right, we want to use fegetround() to get the current rounding mode, and honor that (there are four). In the meantime, I've changed the unit test to explicitly used FE_TOWARDZERO so it passes.

dankamongmen commented 4 years ago

I've removed this functionality from outcurses.