4 ms·
They are perfectly suitable as long as you know what you are doing. Here's a real use case: when compiling a scripting language, map float constants to slots in
by spacechild1 1y ago
They are perfectly suitable as long as you know what you are doing. Here's a real use case: when compiling a scripting language, map float constants to slots in a "constant table" so that all constants with the same value share the same slot.
- zahlman 1y agoIf they are actually compile-time constants and you never have to deduce the value by a runtime calculation, then that is exactly what is meant about treating them as opaque data. Otherwise, prepare for the horror of realizing that `{0.3: 'test'}[0.1 * 3]` (or the syntactic equivalent) fails — in every programming language that lets you try.
- ozgrakkurt 1y agoShouldn’t represent float constants as actual float in a compiler right? Probably better to represent them using some kind of infinite precision decimal