3 ms·
> Sure, decimal would be slower. Would it? I thought dealing with integers - a value, in binary - would be faster than floats - a value in binary, a decimal pl
by nailer 4y ago
> Sure, decimal would be slower.
Would it? I thought dealing with integers - a value, in binary - would be faster than floats - a value in binary, a decimal places value, whatever odd logic there is required to hide the leaky abstraction.
Edit: nevermind. Since the conversation was 'decimal versus float' I thought 'decimal' meant integers without floating points.
If decimals means a decimal point, I think a better suggestion would be to use integers.
- billythemaniam 4y agoIn terms of speed: int > float > decimal. Depends on the hardware type. On GPUs, float > int. However the performance difference is negligible for many, many use cases so I generally use decimal as the default and only use float if absolutely necessary.
- ninepoints 4y agoErr it really depends on what you're doing. Integer division and modulo is still not fast.
- billythemaniam 4y agoDefine "fast" please.
- ClumsyPilot 4y agoOnce you are doing microservices and serving any customer call requires 3 http requests and converting everything into JSON and back every time, it doesnt matter if you use float or int, CPU, GPU, a microcontroller or even abacus by hand.
- dahfizz 4y ago> a value in binary, a decimal places value, whatever odd logic there is required to hide the leaky abstraction. Ironically, this is a much better description of `decimal` than of `float`. IEEE float math is done in hardware. It is "one value in binary" that is added, subtracted, multiplied, etc etc with electric circuits. The decimal abstraction requires manually keeping track of the number of significant digits, converting back and forth so that two different decimals can be added / multiplied, etc etc. There's a lot more that has to happen besides asking the CPU to do a single operation.
- ClumsyPilot 4y agoI do hope we will get a hardware implementation of decimal now that chipmakers dont k ow what to do with the extra transistors and keep coming up with new vector instructions, that most developers dont k ow how to ise and most languages don't even supoort
- dahfizz 4y agoWhich decimal? Fixed point, or floating point? Should the numerator and denominator be given the same bit width? How do you deal with overflow and underflow? Its easy to think of "decimal" as one thing because every language provides a library called `decimal`, but there are a million subtle decisions and tradeoffs to make when choosing one standard binary representation. Most languages don't have a binary representation at all, and implement `decimal` as a high level abstraction with regular integers.
- ClumsyPilot 4y agoPick a solution and make a decision just like it was done with every other format. IEEae has defined one, I believe it was mentioned above
- int_19h 4y agoWe managed to standardize on a single binary floating point representation in practice, and even if it's not perfect, the benefit from such standardization makes it worthwhile.
- t8sr 4y agoIt really depends! Floats are /really/ fast for many operations that are really slow on ints. On modern CPUs, it's faster to cast a number to double, do a square root and cast back to int, than even the cleverest bithacking int algorithm.