comp.lang.ada
 help / color / mirror / Atom feed
* A curiosity about decimal fixed point types...
@ 2013-11-11 15:04 mockturtle
  2013-11-11 17:06 ` Mike H
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: mockturtle @ 2013-11-11 15:04 UTC (permalink / raw)


Dear all,
just a silly curiosity about decimal fixed point types, e.g.,

 type Euro is delta 0.01 digits 20;  
 -- Would be 20 enough? :-)

Are they currently used? Where? Since most of the examples are about money (mine and RM's) included, I guess that they were thought for financial applications, but I am unsure if nowadays financial software uses this type of types or just floating point.

Best regards

Riccardo



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: A curiosity about decimal fixed point types...
  2013-11-11 15:04 A curiosity about decimal fixed point types mockturtle
@ 2013-11-11 17:06 ` Mike H
  2013-11-11 18:54 ` Oliver Kleinke
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Mike H @ 2013-11-11 17:06 UTC (permalink / raw)


In message <7d4f2e0c-0aed-4ba3-aa5a-0c2bc0c2c5a0@googlegroups.com>, 
mockturtle <framefritti@gmail.com> writes
>Dear all,
>just a silly curiosity about decimal fixed point types, e.g.,
>
> type Euro is delta 0.01 digits 20;
> -- Would be 20 enough? :-)
>
>Are they currently used? Where? Since most of the examples are about 
>money (mine and RM's) included, I guess that they were thought for 
>financial applications, but I am unsure if nowadays financial software 
>uses this type of types or just floating point.
Having worked in financial areas before moving into Ada, I would suggest 
that accumulations of rounding errors are a potential mine field for the 
honest and a potential gold mine for the dishonest! In consequence 
rigorous algorithm specification is far more important than most people 
would expect.

Perhaps the ideal is to work in integers (exact figures of the lowest 
denomination of the coinage - pence, cents or w.h.y). But of course, too 
often this is not possible (e.g. currency conversions and discount 
rates) and that is when the problems really start.
-- 
Mike
"Homo sum, humani nihil a me alienum puto" =
"I am human, (so) I (should) judge nothing of humanity to be strange."
Publius Terentius (195/185–159 BC)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: A curiosity about decimal fixed point types...
  2013-11-11 15:04 A curiosity about decimal fixed point types mockturtle
  2013-11-11 17:06 ` Mike H
@ 2013-11-11 18:54 ` Oliver Kleinke
  2013-11-11 19:58 ` AdaMagica
  2013-11-12 12:31 ` Jacob Sparre Andersen
  3 siblings, 0 replies; 7+ messages in thread
From: Oliver Kleinke @ 2013-11-11 18:54 UTC (permalink / raw)


Am Mon, 11 Nov 2013 07:04:12 -0800 (PST)
schrieb mockturtle <framefritti@gmail.com>:

> Dear all,
> just a silly curiosity about decimal fixed point types, e.g.,
> 
>  type Euro is delta 0.01 digits 20;  
>  -- Would be 20 enough? :-)
> 
> Are they currently used? Where? Since most of the examples are about
> money (mine and RM's) included, I guess that they were thought for
> financial applications, but I am unsure if nowadays financial
> software uses this type of types or just floating point.
> 
> Best regards
> 
> Riccardo
> 

Hi Riccardo,

The type definition that you provided is a good example for using fixed
point types for accurate representation. With a fixed-point type you
can avoid the occasional precision problems that floating-point types
suffer from. (For example if I type "0.1 + 0.2" in my
Python-interpreter it yields 0.30000000000000004.)
This can be very important if you sum up/integrate a range of
measurement data obtained from a sensor -- for example a gyro.
Also, on some machines fixed-point arithmetic 'might' be faster than
floating-point arithmetic -- e.g. machines without FPU -- but I guess
that also very much depends on the operations and the compiler, &c.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: A curiosity about decimal fixed point types...
  2013-11-11 15:04 A curiosity about decimal fixed point types mockturtle
  2013-11-11 17:06 ` Mike H
  2013-11-11 18:54 ` Oliver Kleinke
@ 2013-11-11 19:58 ` AdaMagica
  2013-11-12 12:31 ` Jacob Sparre Andersen
  3 siblings, 0 replies; 7+ messages in thread
From: AdaMagica @ 2013-11-11 19:58 UTC (permalink / raw)


Look at
http://en.wikibooks.org/wiki/Ada_Programming/Types/delta
for a description of the differences between ordinary and decimal fixed point arithmetics.

Decimal has precise rules like Cobol (needed for currency), whereas ordinary is less precise.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: A curiosity about decimal fixed point types...
  2013-11-11 15:04 A curiosity about decimal fixed point types mockturtle
                   ` (2 preceding siblings ...)
  2013-11-11 19:58 ` AdaMagica
@ 2013-11-12 12:31 ` Jacob Sparre Andersen
  2013-11-14 13:12   ` Marius Amado-Alves
  3 siblings, 1 reply; 7+ messages in thread
From: Jacob Sparre Andersen @ 2013-11-12 12:31 UTC (permalink / raw)


Riccardo <framefritti@gmail.com> wrote:

>  type Euro is delta 0.01 digits 20;  
>  -- Would be 20 enough? :-)

Depends on your budget and your cash-flow.  For mine it is plenty.

> Are they currently used?

Yes.

> Where?

In 182 out of 119_391 Ada source files (including duplicates) on my laptop.

Reduced to unique type declarations, there is:

   type Decim is delta 0.1 digits 5;
   type Duration is delta 0.001 digits 9 range -24.0 * 3600.0 .. 48.0 * 3600.0;
   type Duration is delta 1.0 digits 9 range -24.0 * 3600.0 .. 48.0 * 3600.0;
   type Kroner is delta 0.01 digits 10;
   type Megabucks is delta 0.01 digits 15;
   type My_Float is delta 0.01 digits 10;
   type Percent is delta 0.01 digits 5 range 0.0 .. 100.0;
   type Push_Data_Type is delta 0.01 digits 7;
   type Real_Val_To_Print is delta 0.01 digits 8;

> Since most of the examples are about money (mine and RM's) included, I
> guess that they were thought for financial applications, but I am
> unsure if nowadays financial software uses this type of types or just
> floating point.

This indicates that they are used for a few more cases than just money
(2 of 9 are money types), but it appears that they aren't all that
common.

Greetings,

Jacob
-- 
"It's not a question of whose habitat it is,
 it's a question of how fast you hit it."


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: A curiosity about decimal fixed point types...
  2013-11-12 12:31 ` Jacob Sparre Andersen
@ 2013-11-14 13:12   ` Marius Amado-Alves
  2013-11-14 14:20     ` gautier_niouzes
  0 siblings, 1 reply; 7+ messages in thread
From: Marius Amado-Alves @ 2013-11-14 13:12 UTC (permalink / raw)


>    type Real_Val_To_Print is delta 0.01 digits 8;

I too use it for printing:-)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: A curiosity about decimal fixed point types...
  2013-11-14 13:12   ` Marius Amado-Alves
@ 2013-11-14 14:20     ` gautier_niouzes
  0 siblings, 0 replies; 7+ messages in thread
From: gautier_niouzes @ 2013-11-14 14:20 UTC (permalink / raw)


> >    type Real_Val_To_Print is delta 0.01 digits 8;
> I too use it for printing:-)

Since it is useful for money and for printing, then it should be perfect for money printing - a big business these days!...
_________________________ 
Gautier's Ada programming 
http://gautiersblog.blogspot.com/search/label/Ada 
NB: follow the above link for a valid e-mail address 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-11-14 14:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-11 15:04 A curiosity about decimal fixed point types mockturtle
2013-11-11 17:06 ` Mike H
2013-11-11 18:54 ` Oliver Kleinke
2013-11-11 19:58 ` AdaMagica
2013-11-12 12:31 ` Jacob Sparre Andersen
2013-11-14 13:12   ` Marius Amado-Alves
2013-11-14 14:20     ` gautier_niouzes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox