3 ms·
For "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 exponen
by fuhsnn 2y ago
For "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 https://ajxs.me/blog/Yamaha_DX7_Technical_Analysis.html
- badmintonbaseba 2y agoPossibly could be combined with C23's _BitInt(N) for the template arguments? I think it's available in clang as a C++ extension. 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.
- seg_fault 2y agoActually you can specify the numeric limits of the mantissa and the exponent. They can be specified as template arguments[0]. So you could do: 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/58f9effbe6c13ab334b05a956ec885edeac89fac/fas/float.hpp#L27 https://github.com/clemensmanert/fas/blob/58f9effbe6c13ab334...
- Archit3ch 2y agoCan you go in the other direction? Higher exponent and mantissa than regular float/double?
- seg_fault 2y agoSure. 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.