Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Error in calculations?
Message
From
12/07/2004 08:15:07
 
 
To
11/07/2004 08:15:53
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00923104
Message ID:
00923254
Views:
20
Hi Rolf,

>Is there a bug in Foxpro/VFP?

I don't know for sure :-)


>
>I have tried this program both in VFP6.0 and FPD2.6 and on two different machines (both running Win98SE), and the results are the same.
>
>Each subtraction adds 1 (one to the 14th decimal position.
>
>I first discovered the problem using addition instead of subtraction; then the increment took place at each 7th iteration.
>
>set decimals to 18
>y = 100.0000000000000000 && 16 zeroes
>set step on
>for n = 1 to 100
> y = y - .1
>next
>
>How can I trust VFP arithmetics after this? I have not made an in-depth study of the problem, so I don’t know if the error only is active when using many decimals.
>

Floating point is stored internally by VFP using IEEE (8 bytes real format). But if you talked about Floating Point, you really should go beyond just VFP. Because even CPU *IS* following the IEEE-754 standard representation (notes: I only talk about 32 bit processor that is fully compatible with MS Product, i.e.: MS Windows).

Floating point will be stored in processor/memory as BCD or Packed BCD (Binary Coded Decimals, max: 10 bytes real format). And IEEE-754 representation is widely acceptable to represent a Floating Point Arithmetic

I don't have any doubt if all programming languages also using IEEE. The fact is, all (current) MS languages using IEEE representation for Floating Point Arithmetic. If you go beyond maximum precision accuracy as presented in IEEE, you'll lose the precision. You can do some workaround, but no matter how you will still lose it, because of CPU size & number of registers limitation.

So... blame it on VFP ? I don't think so ;-)


Here is several documents & info's:

IA-32 Manual (P3-P4)
Chapter 4.7 - BCD and Packed BCD integers
Chapter 4.8 - REAL NUMBERS AND FLOATING-POINT FORMATS
http://www.intel.com/design/Pentium4/manuals/25366515.pdf

AMD Athlon x86 Manual
Chapter 9 - Floating Point Optimizations
http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/22007.pdf

IEEE Floating-Point Representation and MS Languages
http://support.microsoft.com/default.aspx?scid=kb;en-us;36068

IEEE vs. Microsoft Binary Format; Rounding Issues (Complete)
http://support.microsoft.com/default.aspx?scid=kb;en-us;35826

Why Floating Point Numbers May Lose Precision
http://support.microsoft.com/default.aspx?scid=kb;en-us;145889

Precision and Accuracy in Floating-Point Calculations
http://support.microsoft.com/default.aspx?scid=kb;en-us;125056


Sorry for my English
Regards
Herman
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform