[Matrix-SIG] Numeric Nits

Paul F. Dubois dubois1@llnl.gov
Wed, 23 Jun 1999 14:51:45 -0700


<accurate analysis of impending swamp deleted>
> I was thinking that using single-letter appendices at the end of numbers
> to designate non-default types might serve as a solution. E.g.:
>
> 2.4f , 2.4e03f : float (single precision)
> 2.4d == 2.4 , 2.4e03 : double (Python default)
> 32b : 8-bit integer
> 32s : 16-bit integer
> 32i : 32-bit integer
> 32  : 64-bit integer (Python default)
>
<snip>
> Christos Siopis
>
And there you almost have the Fortran 90 solution:
integer, parameter:: normal = selected_real_kind(6,35)
integer, parameter:: precise = selected_real_kind(14, 100)
real(normal) x
real(precise) y
y = real (x, precise)    ! conversion operator
x = 1.23_normal         ! constant, normal precision
real z                            ! default real precision, processor
dependent
z = 3.                            ! default real constant, processor
dependent

Here normal and precise are called "kind parameters". The intrinsic
selected_real_kind is a compile-time-callable function.

The function selected_real_kind returns a "kind parameter" that promises the
given number of decimal digits of accuracy and at least that much exponent
range (e.g. 1e-35 to 1e+35)

If one is going to do anything to Python or Numeric's precision we ought to
go for the gold and be the SECOND language in which it is possible to do
portable numerical programming. The current definition of a default real in
Python is that it is the same as a C double. That is worth knowing but not
actually a guarantee of anything. Basing your programming on the
representation of the number as occupying a certain number of bits is very
odd, if you think about it.