Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Not so logical
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
01422244
Message ID:
01422836
Views:
61
Hi Naomi,

>I don't understand the results. Why the integer part of the second line is 204?

The number 13.4 is the same as 1*10^1 + 3*10^0 + 4*10^-1. Computer store numbers as a series of exponents, not as decimal values. They use 2 as the base, rather then 10. The same number 13.4 in binary form looks like this:

? 2^3+2^2+2^0+2^-2+2^-3+2^-6+2^-7+2^-10+2^-11+2^-14+ ;
2^-15+2^-18+2^-19+2^-22+2^-23+2^-26++2^-27+2^-30+ ;
2^-31+2^-34+2^-35+2^-38+2^-39+2^-42+2^-43

or 1101.0110011001100110011001100110011001100110011

While 13.4 is a finite value in decimal notation, it's an infinite value in the binary system (1100 is repeated) There's no way to precisely store 13.4 as a binary value. Hence, you cannot store 13.4 on a computer, only its approximation. The number above is in decimal notation 13,399999999999980, which is close enough to 13.4 in most cases.

There are two consequences from this. First of all, what we consider a precise and simple value cannot even be stored as a number in many cases on a computer. Calculations with numeric values are always approximations.

The number in the sample had 47 bits. Floating values in VFP are stored in 64 bits. If you change one bit, you don't get a decimal value that is one off, rather a value that looks entirely different. Hence, from a certain point on, many numeric values are equal:

? 2.049999999999999959*100 == 2.050000000000000043*100
? 2.050000000000000044*100 == 2.050000000000000043*100

The first line returns .T., the second one returns .F. because 2.050000000000000043*100 also corresponds to a number of values below 2.05. All values in the range from 2.049999999999999959 to 2.050000000000000043 are the same floating point value and are all identical. That's why the one INT() line returns 204.
--
Christof
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform