comp.lang.ada
 help / color / mirror / Atom feed
* Re: fixed point vs floating point (When do you use it ?)
@ 1997-11-27  0:00 tmoran
  1997-11-27  0:00 ` Robert Dewar
  0 siblings, 1 reply; 4+ messages in thread
From: tmoran @ 1997-11-27  0:00 UTC (permalink / raw)



(thread moved from chat@gnat.com)
>Most obviously, information systems are typically much more appropriately
>programmed using fixed-point
A stocks & commodities database I know of uses fixed point.  Stocks have a
delta of 1/8 (though that is supposed to change to decimal soon) and
different commodities have a bunch of different deltas.




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

* Re: fixed point vs floating point (When do you use it ?)
  1997-11-27  0:00 fixed point vs floating point (When do you use it ?) tmoran
@ 1997-11-27  0:00 ` Robert Dewar
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1997-11-27  0:00 UTC (permalink / raw)



tmoran says

<<A stocks & commodities database I know of uses fixed point.  Stocks have a
delta of 1/8 (though that is supposed to change to decimal soon) and
different commodities have a bunch of different deltas.
>>

The fact that stocks have a delta of 1/8 is NOT a good reason to choose
fixed-point over floating-point for the representation of these values.
In practice all stock values will be model numbers of any reasonable
floating-point type, so the issue of accurate representation does not 
arise. What is important is the computations that you propose to perform
on these values. I would guess that for most purposes, it is better to
use floating-point for stock prices than fixed-point (of course if you
are in COBOL, you have little choice, and indeed stock prices don't fit
nicely into COBOL, which has no provision for binary fixed-point).





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

* Re: fixed point vs floating point (When do you use it ?)
@ 1997-11-28  0:00 tmoran
  1997-11-28  0:00 ` Robert Dewar
  0 siblings, 1 reply; 4+ messages in thread
From: tmoran @ 1997-11-28  0:00 UTC (permalink / raw)



In <dewar.880662487@merv> Robert Dewar said:
>In practice all stock values will be model numbers of any reasonable
>floating-point type, so the issue of accurate representation does not
>arise. What is important is the computations that you propose to perform
>on these values. I would guess that for most purposes, it is better to
>use floating-point for stock prices than fixed-point (of course if you

  1) Soon stock prices will be in decimal, and thus not accurately
representable by binary floating point types.  That's already the case for
various commodity prices.  2) For a historical price database, space
matters, and fixed point types, depending on the compiler, are in this
case easier to store in a substantially smaller number of bytes.  (As I
recall, there's only one stock price that doesn't fit in 16 bits with a
delta, and small, of 1/8, not counting adjusting the historical record for
splits etc.) 3) This database was already in this form.  4) Most of the
processing of data of this sort is comparisons, multiplication or division
by integers, or addition/subtraction.  Division of one stock price by
another is relatively rare, and thus not timing critical, and
multiplication of two stock or commodity prices together is even rarer.
So any speed advantage of */ fpt on some new machines is not usually
important.




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

* Re: fixed point vs floating point (When do you use it ?)
  1997-11-28  0:00 tmoran
@ 1997-11-28  0:00 ` Robert Dewar
  0 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1997-11-28  0:00 UTC (permalink / raw)



<<  1) Soon stock prices will be in decimal, and thus not accurately                           
representable by binary floating point types.  That's already the case for                   
various commodity prices.  2) For a historical price database, space                         
matters, and fixed point types, depending on the compiler, are in this                       
case easier to store in a substantially smaller number of bytes.  (As I                      
recall, there's only one stock price that doesn't fit in 16 bits with a                      
delta, and small, of 1/8, not counting adjusting the historical record for                   
splits etc.) 3) This database was already in this form.  4) Most of the                      
processing of data of this sort is comparisons, multiplication or division                   
by integers, or addition/subtraction.  Division of one stock price by                        
another is relatively rare, and thus not timing critical, and                                
multiplication of two stock or commodity prices together is even rarer.                      
So any speed advantage of */ fpt on some new machines is not usually                         
important.                                                                                   
>>


First, there is nothing special about binary scaling with respect to
fixed-point. Ada 95 (at least in a full featured implementation such
as GNAT) fully supports decimal fixed-point, as well as ordinary
fixed-point with decimal small values. The former is attractive since
it has deterministic arithmetic semantics, while the latter does not.

Many manipulations of stock prices involve complex calculations, including
computing weighted averages, for which floating-point will be more suitable
(for example, computing the time weighted rate of return, as described in
my paper in Management Science, definitely prefers floating-point, which is
why when I was writing COMVEST, a pension fund portfolio analysis program,
using the TWRR extensively, for the Banking Administration Institute, we
decided to use Fortran instead of COBOL, since we really needed fpt.
Boy that was a long time ago now, the paper is 1971, "An axiomatic
characterization of the Time-Weighted Rate of Return, Vol18, #2).
Of course today, I would prefer to use Ada for COMVEST, but we would
still use floating-point for representing stock prices in that context.

That's not to say that scaled fixed-point might not be more suitable for
some purposes, and certainly for compact external storage, it is a reasonable
medium to choose, although please note that stock prices are sometimes in
1/16 or 1/32 these days, so a uniform scaling in 16-bits is not practical!





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

end of thread, other threads:[~1997-11-28  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-11-27  0:00 fixed point vs floating point (When do you use it ?) tmoran
1997-11-27  0:00 ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1997-11-28  0:00 tmoran
1997-11-28  0:00 ` Robert Dewar

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