Operating System - OpenVMS
1751710 Members
5068 Online
108781 Solutions
New Discussion юеВ

Re: using fortran and profor with upgraded VMS and Oracle

 
Barry Alford
Frequent Advisor

Re: using fortran and profor with upgraded VMS and Oracle

You may be better off using the Fortran intrinsic functions HUGE(x) and TINY(x) where x is a real of the required type - REAL(16) for you
robert70
Valued Contributor

Re: using fortran and profor with upgraded VMS and Oracle

Mike

do you have the values for the 4, 8 and reals?

real*4 max and mins?
real*8 max and mins?

thanks
Mike Kier
Valued Contributor

Re: using fortran and profor with upgraded VMS and Oracle

Sure, but you can get them yourself very easily - just compile and run the following with different values for the /FLOAT qualifier on the compiler:

type *, 'TINY16', tiny(0.0_16), 'HUGE', huge(0.0_16)
type *, 'TINY8 ', tiny(0.0_8), 'HUGE', huge(0.0_8)
type *, 'TINY4 ', tiny(0.0_4), 'HUGE', huge(0.0_4)
end

For /FLOAT=D_FLOAT I get:

TINY16 3.362103143112093506262677817321753E-4932 HUGE
1.189731495357231765085759326628007E+4932
TINY8 2.9387358770557188E-39 HUGE 1.7014118346046923E+38
TINY4 2.9387359E-39 HUGE 1.7014117E+38

For /FLOAT=G_FLOAT I get:

TINY16 3.362103143112093506262677817321753E-4932 HUGE
1.189731495357231765085759326628007E+4932
TINY8 5.562684646268003E-309 HUGE 8.988465674311579E+307
TINY4 2.9387359E-39 HUGE 1.7014117E+38

For /FLOAT=IEEE_FLOAT I get

TINY16 3.362103143112093506262677817321753E-4932 HUGE
1.189731495357231765085759326628007E+4932
TINY8 2.225073858507201E-308 HUGE 1.797693134862316E+308
TINY4 1.1754944E-38 HUGE 3.4028235E+38

And ideally you would not hardcode the values in your program - use the HUGE and TINY intrinsics to initialize real variables instead of Parameters at program start-up.

Please tell me you're not using extended precision floating-point for monetary calculations...

BTW: This is on OpenVMS Alpha V7.3-2 and Fortran V7.5-1961
Practice Random Acts of VMS Marketing
John Gillings
Honored Contributor

Re: using fortran and profor with upgraded VMS and Oracle

Robert,

Please heed Mike's advice:

"Please tell me you're not using extended
precision floating-point for monetary
calculations..."

No matter how much floating point precision you have, you WILL get calculation errors. There's nothing you can do about it, it's the nature of finite precision floating point representation. FPFPR is great for scientific and engineering work, but it just plain doesn't work for financial stuff. This is not debatable, and I don't care how long you've been doing it - you shouldn't!

If you're doing money calculations, forget all REAL types. In Fortran you can use 64 bit INTEGER types scaled to your smallest unit (cents or tenths of cents).

If you don't believe me, try this simple test... manually convert $0.10c (decimal) into 32 or 64 bit binary floating point, now convert it back.
A crucible of informative mistakes
robert70
Valued Contributor

Re: using fortran and profor with upgraded VMS and Oracle

Thanks Mike,
Why does the compiler not like this?

real*16 max_real_16
max_real_16 = huge(max_real_16)

Thanks
Robert
robert70
Valued Contributor

Re: using fortran and profor with upgraded VMS and Oracle

ignore that last question mike got that now with

real*16 max_real_16
parameter (max_real_16 = huge(0.0_16))
Dennis Handly
Acclaimed Contributor

Re: using fortran and profor with upgraded VMS and Oracle

>John: No matter how much floating point precision you have, you WILL get calculation errors

Not if you are using decimal floating point. :-)
John Gillings
Honored Contributor

Re: using fortran and profor with upgraded VMS and Oracle

re: Dennis,

>decimal floating point

True, but I'm specificically talking about BINARY FPFPR, which is all you get in Fortran and C.

In languages that support a Binary Coded Decimal (BCD) data types, like COBOL and BASIC, you can safely use them for monetary calculations, but in (for example) Fortran, C and Pascal where floating point is finite precision binary, it's very important that programmers understand the limitations of FPFPR arithmetic. Just one example, I'd contend that when using these data types, any code comparing two FPFPR variables for equality (".EQ." or "==") is almost certainly incorrect.

I'm concerned that the reason Robert is using (very) high precision data types (REAL*16) in this example is an attempt to "fix" the kind of errors which are inherent in the data type. It's fine for calculating load values on bridges, or astronomical distances, but NOT for calculating cap values for stocks or bank balances!
A crucible of informative mistakes
Dennis Handly
Acclaimed Contributor

Re: using fortran and profor with upgraded VMS and Oracle

>John: which is all you get in Fortran and C.
>but in (for example) Fortran, C and Pascal where floating point is finite precision binary

The next C Standard supports Decimal Floating Point and this is implemented on HP-UX 11.31.

>it's very important that programmers understand the limitations of FPFPR arithmetic.

Exactly, I learned that many decades ago.

>but NOT for calculating cap values for stocks or bank balances!

That's why DecFP was added to C.