smaller float

Juan Jose Comellas jcomellas at gmail.com
Mon Aug 21 07:52:20 PDT 2006


You could use shorts, ints or longs with fixed point precision in a custom
made class, either in base 10 or base 2. In base 10, using 2 digits for
decimals, it would mean that a number like 12345 should be considered as
123.45. It's pretty easy to implement this. You just have to remember
to "normalize" (i.e. adjust the number to the proper number of decimals)
each number after an operation that will expand the amount of decimals,
such as multiplications.


nobody_ wrote:

> I only need something like two decimal precision on only small numbers, so
> I use:
> 
> cast(double) short / 100.0
> 
> I don't want to use floats as they use too much memory (talking about a
> 20000 big array).
> Why are there no 16bit halfs (as opposed to doubles :)?




More information about the Digitalmars-d-learn mailing list