smaller float

nobody_ spam at spam.spam
Mon Aug 21 13:35:47 PDT 2006


I'm sorry, I'm not sure whether I get your reply :)
Is what you propose different than doing:

short s=0;

s++100; //s++1.00
s*3

x=x+(s/100.0); // divide it when it is used

My way is not really nice as you need to divide it every time you use it.
How would, what you propose, work?
(sorry about not getting your post :(

"Juan Jose Comellas" <jcomellas at gmail.com> wrote in message 
news:ecchb5$2p26$1 at digitaldaemon.com...
> 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