Show HN: Floating point arithmetic types in C++ for any size and any base
github.com
Show HN: Floating point arithmetic types in C++ for any size and any base
1–10 of 42 posts
Re: Show HN: Floating point arithmetic types in C++ for any size and any base
#2Re: Show HN: Floating point arithmetic types in C++ for any size and any base
#3Re: Show HN: Floating point arithmetic types in C++ for any size and any base
#4> TODO: (configurable) rounding support
What's the default rounding mode? Round to nearest even?
You might be interested in https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p33... too, which is a recent paper for introducing reproducible floating point to C++.
Very small floating point types can be handy for exhaustive testing of floating point function templates, especially ones that take multiple arguments. Walking over all floating point values for a small type often finds most if not all corner cases that can manifest with a floating point type of any size.
Re: Show HN: Floating point arithmetic types in C++ for any size and any base
#5For "any size" I was kind of expecting arbitrary sized mantissa/exponent, can be useful for emulating weird DACs, for example, 12-bit mantissa and 3-bit exponent[1]. [1] https://ajxs.me/blog/Yamaha_DX7_Technical_Analysis.html
edit: or I guess you could have your own Tmantissa and Texponent types as custom classes that correctly model _BitInt(N), they don't seem to be required to be builtin integral types.
Re: Show HN: Floating point arithmetic types in C++ for any size and any base
#6Re: Show HN: Floating point arithmetic types in C++ for any size and any base
#7https://en.cppreference.com/w/cpp/types/is_fundamental
https://en.cppreference.com/w/cpp/types/is_floating_point
https://en.cppreference.com/w/cpp/types/is_arithmetic
Re: Show HN: Floating point arithmetic types in C++ for any size and any base
#8Nice! > TODO: (configurable) rounding support What's the default rounding mode? Round to nearest even? You might be interested in https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p33... too, which is a recent paper for introducing reproducible floating point to C++. Very small floating point types can be handy for exhaustive testing of floating point function templates, especially ones that take multiple argu…
Thanks for the hint to the paper. I also faced these issues. Thus, I provided a constructor which accepts mantissa and exponent as values. Very handy for the unittests.
Re: Show HN: Floating point arithmetic types in C++ for any size and any base
#9For "any size" I was kind of expecting arbitrary sized mantissa/exponent, can be useful for emulating weird DACs, for example, 12-bit mantissa and 3-bit exponent[1]. [1] https://ajxs.me/blog/Yamaha_DX7_Technical_Analysis.html
Float // highest possible value of the exponent
The Float then simulates an unsigned 12bit mantissa and a 3bit exponent. Sure it still takes 16 bytes. But you could create a union with bitfields where you shrink that even further.[0] https://github.com/clemensmanert/fas/blob/58f9effbe6c13ab334...
Re: Show HN: Floating point arithmetic types in C++ for any size and any base
#10Have nothing to say other than - neat!