> 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.
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.
https://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
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.
Float<uint8_t, // type of the mantissa
uint8_t, // type of the exponent
0, // lowest possible value of the mantissa
4095, // highest possible value of the mantissa
0, // lowest possible value of the exponent
7> // 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...
> If the program adds specializations for std::is_fundamental or std::is_fundamental_v, the behavior is undefined.
This is an oversimplification. The actual rule is https://eel.is/c++draft/library#namespace.std-2 .
> the specialization meets the standard library requirements for the original template.
For is_fundamental<YourClassType> it means that is_fundamental<YourClassType>::value must be false, as YourClassType is not a fundamental type, as defined in https://eel.is/c++draft/basic.fundamental#17 .
Some traits are just not designed to be customization points.
Rounding to nearest with an odd base doesn't seem to be as straightforwardly implementable from rounding to zero calculations at a higher precision.
Float<int64_t, int64_t>
Gives you a signed Mantissa with 64 bit and a signed Exponent with 64bit. Since there are numeric limits for int64_t available, Float knows the max and the min value.You could get even bigger ranges for Float by implementing your own big integer type.
https://www.boost.org/doc/libs/1_86_0/libs/multiprecision/do...
https://www.boost.org/doc/libs/1_86_0/libs/multiprecision/do...
Surely you mean ::max()?
> is_fundamental<int16_t, int16_t>::value et al.
Besides the undefined behavior issue mentioned by others, none of these are syntactially correct.
> #include "fas/stream.hpp>
Ok then...
> The Stl's std::numeric_limits is required the limits of the specified types for mantissa and exponent.
Missing a word? Also, the STL [0] does not have std::numeric_limits, perhaps you mean the C++ standard library (or stdlib for short).
However, this is not exposed in all GMP wrappers.
If you really don’t want the copyrights, you can use the CC0 license from Creative Commons. That would allow people to use your code any way they want with no restrictions (which means they are legally allowed to use it commercially, remove the author notice, re-license modified versions, redistribute the code, etc.). However, you do not need to waive your copyrights entirely in order to license your code as open source. You can choose between a variety of licensing terms, while still being very open and liberal about sharing. Try the Creative Commons license chooser https://chooser-beta.creativecommons.org/. Or look through open source licenses. Standardized SPDX IDs are gaining popularity since it helps with some automation workflows. https://opensource.org/licenses https://spdx.org/licenses/
Since you left the author note, maybe you would like an attribution license like one of these popular choices (both available with SPDX IDs): https://opensource.org/license/bsd-3-clause https://creativecommons.org/licenses/by-sa/4.0/
If you don’t add a license, then your code remains under strict copyright and people are not legally allowed to use it in their own projects, regardless of whether you have a copyright notice in the comments. Leaving out the copyright notice might be confusing, especially given this thread. The recommended practice is to include both the copyright notice and the license in comments or a license file.
In fas you have to specify the sizes (of mantissa and exponent) during compile time. So the size of this type is fixed. Thus, there is no heap involved.
That's why it's called https://en.wikipedia.org/wiki/Clean-room_design.