Given the following program, which works if and only if the compiler
allows higher than double precision, I was surprised to find that a
certain compiler, for which pdp = 15, php = 18, printed y with only
8 correct significant digits instead of the 15 or 16 I had expected.
Intel and Sun f95, for both of which pdp = 15, php = 33, printed y
with 16 correct digits. IMHO that was correct.
Has the first compiler a bug or have I misread the f95 standard?
PROGRAM testprecision1 ! hp = higher than double precision if possible.
IMPLICIT NONE ! Should y have pdp good digits?
INTEGER ,PARAMETER :: dp = kind(1d0), pdp = precision(1._dp), &
hp = selected_real_kind(pdp+1), php = precision(1._hp)
REAL(hp) :: x = 1/9._hp, y
CHARACTER:: fmt*24 ! Format that will depend on the value of php
PRINT *,'DP kind',dp,'precision',pdp,' HP kind',hp,'precision',php
WRITE(fmt,"(A,2(I0,A))") '(" ",A," = ",F',php+3,'.',php+1,')'
y = 2*real(x,dp)
PRINT fmt, 'x',x,'y',y
PRINT "(7X,A)",'....v....1....v....2....v....3....v'
END PROGRAM testprecision1
-- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@vuw.ac.nz phone (+64)(4)463 5662 fax (+64)(4)463 5045
|
|
0
|
|
|
|
Reply
|
harper (718)
|
2/23/2008 1:36:23 AM |
|
John Harper <harper@mcs.vuw.ac.nz> wrote:
> Given the following program, which works if and only if the compiler
> allows higher than double precision, I was surprised to find that a
> certain compiler, for which pdp = 15, php = 18, printed y with only
> 8 correct significant digits instead of the 15 or 16 I had expected.
> Intel and Sun f95, for both of which pdp = 15, php = 33, printed y
> with 16 correct digits. IMHO that was correct.
>
> Has the first compiler a bug or have I misread the f95 standard?
>
> PROGRAM testprecision1 ! hp = higher than double precision if possible.
> IMPLICIT NONE ! Should y have pdp good digits?
> INTEGER ,PARAMETER :: dp = kind(1d0), pdp = precision(1._dp), &
> hp = selected_real_kind(pdp+1), php = precision(1._hp)
> REAL(hp) :: x = 1/9._hp, y
> CHARACTER:: fmt*24 ! Format that will depend on the value of php
> PRINT *,'DP kind',dp,'precision',pdp,' HP kind',hp,'precision',php
> WRITE(fmt,"(A,2(I0,A))") '(" ",A," = ",F',php+3,'.',php+1,')'
> y = 2*real(x,dp)
> PRINT fmt, 'x',x,'y',y
> PRINT "(7X,A)",'....v....1....v....2....v....3....v'
> END PROGRAM testprecision1
Intriguing. So I see. Simpler versions also exhibit the same phenomenon.
It's a little hard for me to pin down what triggers it and why. Looks to
me like you are reading it fine.
Well, ok, to be pedantic, the standard doesn't guarantee that you get
much of any precision at all in any operation. Just because a kind can
represent reals with 15 digits of accuracy doesn't guarantee that any of
the operations are accurate to even 1 digit. But that's purely academic.
I think it pretty clear that someting isn't working as intended with
compiler number 1 (which, oddly, seems to match the behavior of the
first compiler I tried).
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
|
|
0
|
|
|
|
Reply
|
nospam47 (9742)
|
2/23/2008 2:02:48 AM
|
|
John Harper wrote:
> Given the following program, which works if and only if the compiler
> allows higher than double precision, I was surprised to find that a
> certain compiler, for which pdp = 15, php = 18, printed y with only
> 8 correct significant digits instead of the 15 or 16 I had expected.
> Intel and Sun f95, for both of which pdp = 15, php = 33, printed y
> with 16 correct digits. IMHO that was correct.
>
> Has the first compiler a bug or have I misread the f95 standard?
>
> PROGRAM testprecision1 ! hp = higher than double precision if possible.
> IMPLICIT NONE ! Should y have pdp good digits?
> INTEGER ,PARAMETER :: dp = kind(1d0), pdp = precision(1._dp), &
> hp = selected_real_kind(pdp+1), php = precision(1._hp)
> REAL(hp) :: x = 1/9._hp, y
> CHARACTER:: fmt*24 ! Format that will depend on the value of php
> PRINT *,'DP kind',dp,'precision',pdp,' HP kind',hp,'precision',php
> WRITE(fmt,"(A,2(I0,A))") '(" ",A," = ",F',php+3,'.',php+1,')'
> y = 2*real(x,dp)
> PRINT fmt, 'x',x,'y',y
> PRINT "(7X,A)",'....v....1....v....2....v....3....v'
> END PROGRAM testprecision1
>
Output from WIN32 gfortran (gcc version 4.3.0 20070824 (experimental)
(GCC)) seems to be what you expect.
DP kind 8 precision 15 HP kind 10 precision
18
x = 0.1111111111111111111
y = 0.2222222222222222099
....v....1....v....2....v....3....v
|
|
0
|
|
|
|
Reply
|
baf (63)
|
2/23/2008 6:45:37 AM
|
|
On 23 f=E9v, 02:36, har...@mcs.vuw.ac.nz (John Harper) wrote:
> Given the following program, which works if and only if the compiler
> allows higher than double precision, I was surprised to find that a
> certain compiler, for which pdp =3D 15, php =3D 18, printed y with only
> 8 correct significant digits instead of the 15 or 16 I had expected.
> Intel and Sun f95, for both of which pdp =3D 15, php =3D 33, printed y
> with 16 correct digits. IMHO that was correct.
>
> Has the first compiler a bug or have I misread the f95 standard?
>
> PROGRAM testprecision1 ! hp =3D higher than double precision if possible.
> IMPLICIT NONE ! Should y have pdp good digits?
> INTEGER ,PARAMETER :: dp =3D kind(1d0), pdp =3D precision(1._dp), &
> hp =3D selected_real_kind(pdp+1), php =3D precision(1._hp)
> REAL(hp) :: x =3D 1/9._hp, y
> CHARACTER:: fmt*24 ! Format that will depend on the value of php
> PRINT *,'DP kind',dp,'precision',pdp,' HP kind',hp,'precision',php
> WRITE(fmt,"(A,2(I0,A))") '(" ",A," =3D ",F',php+3,'.',php+1,')'
> y =3D 2*real(x,dp)
> PRINT fmt, 'x',x,'y',y
> PRINT "(7X,A)",'....v....1....v....2....v....3....v'
> END PROGRAM testprecision1
>
> -- John Harper, School of Mathematics, Statistics and Computer Science,
> Victoria University, PO Box 600, Wellington 6140, New Zealand
> e-mail john.har...@vuw.ac.nz phone (+64)(4)463 5662 fax (+64)(4)463 5045
It looks like a compiler bug. Instead of REAL(x,dp), I also tried
DBLE(x) with the same result (only 8 digits) instead of 16 with other
compilers like ifort and gfortran.
You should report it to Andy ...
|
|
0
|
|
|
|
Reply
|
francois.jacq (304)
|
2/23/2008 10:13:33 AM
|
|
|
3 Replies
36 Views
(page loaded in 0.119 seconds)
Similiar Articles: FPC: A High-Speed Compressor for Double-Precision Floating-Point ...This paper by Martin Burtscher is scheduled for publication in IEEE Tran. on Computers, with the following abstract: "Many scientific programs exchan... Floating point problem (again) - comp.lang.asm.x86The only exception I can think of is for programs that deal with LOTS of floating point data where double precision is not required and the memory size difference between ... How force simulation with 32b floating (simple precision) - comp ...gfortran or ifort? - comp.lang.fortran Most of what I do is single precision, and is not very floating-point ... poster indicated, you can always force the ... Large numbers, floating point number questions - comp.lang.c ...> > > > Floating-point gives up some precision to get greater range. > > The larger the number, the less precisely it can represent it. > > > > Consider a small, simplified ... Floating Point and printf() - comp.lang.asm.x86GENERAL: PRECISION OF PRINTF %F FORMAT STRING SYMPTOMS: I understand that the single precision floating-point values only have a 24-bit mantissa, but the printf %f float ... 16 bit floating points - comp.graphics.api.openglIn IEEE 754-2008 the 16-bit base 2 format is officially referred to as binary16. It is intended for storage (of many floating-point values where higher precision need not ... Anyone used the Xilinx' floating point core? - comp.arch.fpga ...All Digital PLL - comp.arch.fpga I assume you mean double-precision floating point when you say ... IPCORE source code - comp.arch.fpga microblaze spi core problem - comp ... Retaining precision after subtraction - comp.soft-sys.matlab ...Can anyone tell me how to retain the precision of the calculation ? > > Thanks in advance ----- It is inherent in double precision floating point numbers ... Max integer in a floating point type? - comp.lang.c++.moderated ...For 32-bit (single precision IEEE) floating point, X is 16777216.0. For 64-bit (double precision IEEE), X is 9007199254740992.0. The corresponding minimum value for a ... VisualC++ vs GCC: read in a number in exponential notation - comp ...... need to read: "What Every Computer Scientist Should Know About Floating-Point ... to set some project settings in Visual Studio that has to do with floating point accuracy ... Floating point - Wikipedia, the free encyclopediaFor example, the decimal number 0.1 is not representable in binary floating-point of any finite precision; the exact binary representation would have a "1100" sequence ... Single-precision floating-point format - Wikipedia, the free ...Single-precision floating-point format is a computer number format that occupies 4 bytes (32 bits) in computer memory and represents a wide dynamic range of values by ... 7/27/2012 7:18:47 PM
|