Thread overview
smaller float
Aug 21, 2006
nobody_
Aug 21, 2006
Juan Jose Comellas
Aug 21, 2006
nobody_
Aug 27, 2006
nobody_
August 21, 2006
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 :)?


August 21, 2006
nobody_ wrote:

> Why are there no 16bit halfs (as opposed to doubles :)? 

There are, they're just not built-in to the D language...

http://en.wikipedia.org/wiki/Half_precision ("half", 16)

Wasn't any interest shown for adding 16 or 128 bit types.

http://en.wikipedia.org/wiki/Quad_precision ("quad", 128)

--anders
August 21, 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 :)?

August 21, 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@gmail.com> wrote in message news:ecchb5$2p26$1@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 :)?
> 


August 27, 2006
"nobody_" <spam@spam.spam> wrote in message news:ecc297$2943$1@digitaldaemon.com...

> I don't want to use floats as they use too much memory (talking about a 20000 big array).

With floats, that's 80kb.  I'm hoping you have that much RAM.


August 27, 2006
>> I don't want to use floats as they use too much memory (talking about a
>> 20000 big array).
>
> With floats, that's 80kb.  I'm hoping you have that much RAM.


Sorry... left out a zero :)
(plus its quite an extensive structure)
I remember that the array was quite big with floats, but maybe I need to
check that agian yeah :)

I imagine that dividing through 10^(x) is a really easy(optimized) operation, right?