- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We are finding some awkward rounding going on with real numbers
For example our program has
real beta
beta = 1.0
real betastep
betastep = 0.01
but when you examine with the debugger betastep = 9.9999998E-3, which is not quite the same
unfortuantely this showing up in our results - after a number of loops of
beta = beta - betastep
the beta counter drifts off
5.98004 instead of 5.98, 4.63001 instead of 4.63 etc
I've tried the /fp:strict and /fp:precise and /Qfp_port compiler switches, but they dont seem to change anything
Is there an easy fix?
Or is it just 'one-of-those' rounding things?
Thankx
Jim
For example our program has
real beta
beta = 1.0
real betastep
betastep = 0.01
but when you examine with the debugger betastep = 9.9999998E-3, which is not quite the same
unfortuantely this showing up in our results - after a number of loops of
beta = beta - betastep
the beta counter drifts off
5.98004 instead of 5.98, 4.63001 instead of 4.63 etc
I've tried the /fp:strict and /fp:precise and /Qfp_port compiler switches, but they dont seem to change anything
Is there an easy fix?
Or is it just 'one-of-those' rounding things?
Thankx
Jim
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Real numbers can rarely be expressed exactly in binary, so this problem is typical of working with reals.
Is your example typical of what you want to do - always an exact number of steps (in this case 100).
Suggest that you use an integer counter, and calculate
Beta = Betastart - (I-1)*Betastep
or something silimar.
Regards,
David
Is your example typical of what you want to do - always an exact number of steps (in this case 100).
Suggest that you use an integer counter, and calculate
Beta = Betastart - (I-1)*Betastep
or something silimar.
Regards,
David
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You could delay the drift (at lest I would think so) ifyou use double precission.
real(8) beta = 1.0d
real(8) betastep=0.01d
Regards
Lars
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You're dealing with limitations of IEEE 754 Standard. In case of a single-precision data type ( 24-bit precision) a rounding or inexact
issues start affecting a precision very quickly. The only solution is touse a double-precision data type ( 53-bit or 64-bitprecisions ) instead.
Best regards,
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Depending on what you are looking for, the "easy fix" might resemble;
do i = 1,100
beta = (100 - i) / 100.
.....
Not only would this avoid drift, it is a classic vectorizability transformation.
I think David (in the earlier response) may have meant this.
do i = 1,100
beta = (100 - i) / 100.
.....
Not only would this avoid drift, it is a classic vectorizability transformation.
I think David (in the earlier response) may have meant this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
real beta, betaBase
betaBase = 1.0
real betaStepMultiplier, betaStepInverse
betaStepMultiplier = 0.0
betaStepInverse = 100.0
do I=1,N
beta = betaBase - (betaStepMultiplier / betaStepInverse)
...
betaStepMultiplier = betaStepMultiplier + 1.0
end do
The above will provide better precision, and more importantly, will not accumulate roundoff errors.
Note, division is relatively fast on current processors.
Jim Dempsey
betaBase = 1.0
real betaStepMultiplier, betaStepInverse
betaStepMultiplier = 0.0
betaStepInverse = 100.0
do I=1,N
beta = betaBase - (betaStepMultiplier / betaStepInverse)
...
betaStepMultiplier = betaStepMultiplier + 1.0
end do
The above will provide better precision, and more importantly, will not accumulate roundoff errors.
Note, division is relatively fast on current processors.
Jim Dempsey

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page