digitalmars.D.learn - smaller float
- nobody_ (6/6) Aug 21 2006 I only need something like two decimal precision on only small numbers, ...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (6/7) Aug 21 2006 There are, they're just not built-in to the D language...
- Juan Jose Comellas (8/16) Aug 21 2006 You could use shorts, ints or longs with fixed point precision in a cust...
- nobody_ (11/29) Aug 21 2006 I'm sorry, I'm not sure whether I get your reply :)
- Jarrett Billingsley (3/5) Aug 26 2006 With floats, that's 80kb. I'm hoping you have that much RAM.
- nobody_ (6/9) Aug 27 2006 Sorry... left out a zero :)
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 :)?
Aug 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
Aug 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 :)?
Aug 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 :)?
Aug 21 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.
Aug 26 2006
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?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.
Aug 27 2006