Re: [fpc-pascal] Re: Why this evaluates on if wrong ? (GMP)

2007-10-31 Thread Vinzent Hoefler
On Tuesday 30 October 2007 17:31, Inga Petuhhov wrote: A copy-paste from Python Shell: a = 1 a 1 a = a + 0.4 a 1.3999 a = a - 0.4 a 0.99989 a == 1 False Or a bit more simple (and for some maybe even more surprising): 1.0 == 0.4 - 0.4 + 1.0 True

[fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-31 Thread Musan Antal
The discussion about PI reminds me another funny quote: The primary purpose of the DATA statement is to give names to constants; instead of referring to pi as 3.141592653589793 at every appearance, the variable PI can be given that value with a DATA statement and used instead of the longer form

Re: [fpc-pascal] Re: Why this evaluates on if wrong ? (more pi fun)

2007-10-31 Thread Tom Verhoeff
On Tue, Oct 30, 2007 at 07:36:39PM +0200, Musan Antal wrote: The discussion about PI reminds me another funny quote: The primary purpose of the DATA statement is to give names to constants; instead of referring to pi as 3.141592653589793 at every appearance, the variable PI can be given that

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-31 Thread Germán Pablo Gentile - PetroBox
El mar, 30-10-2007 a las 19:36 +0200, Musan Antal escribió: Oh, my GOD! I hope, in the current eternity, no change in the value of pi might occur! I bet the circles will never will be the same if that happens.:P ___ fpc-pascal maillist -

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-30 Thread Germán Pablo Gentile - PetroBox
El mar, 30-10-2007 a las 02:28 +0100, mm escribió: Joao Morais a écrit : Daniël Mantione wrote: And, as said before, no datastructure is adequate for storing a mathematical real number. Not even if you have infinite memory. Nope. If infinite memory was tangible, you would be able to

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-30 Thread mm
Germán Pablo Gentile - PetroBox a écrit : El mar, 30-10-2007 a las 02:28 +0100, mm escribió: Joao Morais a écrit : Daniël Mantione wrote: And, as said before, no datastructure is adequate for storing a mathematical real number. Not even if you have infinite memory. Nope. If infinite memory

Re: [fpc-pascal] Re: Why this evaluates on if wrong ? (GMP)

2007-10-30 Thread Andrea Mauri
But someone tried to reproduce the example with other programming languages? mm ha scritto: Tom Verhoeff a écrit : In fact, the GMP (GNU Multiple Precision Arithmetic Library gmplib.org) offers this and more. Unfortunately, there does not seem to be a complete FreePascal interface for

Re: [fpc-pascal] Re: Why this evaluates on if wrong ? (GMP)

2007-10-30 Thread Inga Petuhhov
A copy-paste from Python Shell: a = 1 a 1 a = a + 0.4 a 1.3999 a = a - 0.4 a 0.99989 a == 1 False Best regards Inga PS I always talk to my informatics-students: You never-ever do with real-variables something like this: if real1 = real2 then ... Real numbers

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread L
It's just one more funny thing one must realize, when comparing real numbers with some exact real constants. After this, I will try to never compare doubles directly, but using tricks like above. Because, in this digital world 1 + 0.4 - 0.4 1. My opinion: This is ludicrous. The end user

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread Michael Van Canneyt
On Mon, 29 Oct 2007, L wrote: It's just one more funny thing one must realize, when comparing real numbers with some exact real constants. After this, I will try to never compare doubles directly, but using tricks like above. Because, in this digital world 1 + 0.4 - 0.4 1. My

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread L
The programmer definitely should care. He has to make the right choice in what type he chooses, so he must be aware of any 'quircks' of the type he is using, and that includes how things are rounded and how they are stored in memory. That's why there are IEEE references for this. It's his

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread Jonas Maebe
On 29 Oct 2007, at 15:30, L wrote: It's just one more funny thing one must realize, when comparing real numbers with some exact real constants. After this, I will try to never compare doubles directly, but using tricks like above. Because, in this digital world 1 + 0.4 - 0.4 1. My opinion:

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread Daniël Mantione
Op Mon, 29 Oct 2007, schreef L: It's just one more funny thing one must realize, when comparing real numbers with some exact real constants. After this, I will try to never compare doubles directly, but using tricks like above. Because, in this digital world 1 + 0.4 - 0.4 1. My

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread L
Your Casio doesn't do comparisons. Just round to 10 digits before you compare and it'll work just as fine as on your Casio. Daniël And some off topic trivia: My casio says 10 + 2 digits near the model number. Does this mean it displays 10 digits and stores 2 in the background, or that I

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread Michael Van Canneyt
On Mon, 29 Oct 2007, L wrote: The programmer definitely should care. He has to make the right choice in what type he chooses, so he must be aware of any 'quircks' of the type he is using, and that includes how things are rounded and how they are stored in memory. That's why there are

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread Daniël Mantione
Op Mon, 29 Oct 2007, schreef L: Your Casio doesn't do comparisons. Just round to 10 digits before you compare and it'll work just as fine as on your Casio. Daniël And some off topic trivia: My casio says 10 + 2 digits near the model number. Does this mean it displays 10

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread Tom Verhoeff
On Mon, Oct 29, 2007 at 07:30:03AM -0700, L wrote: It's just one more funny thing one must realize, when comparing real numbers with some exact real constants. After this, I will try to never compare doubles directly, but using tricks like above. Because, in this digital world 1 + 0.4

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread L
The end user is using a high level language and should not care whether the computer is digital or analog. Unfortunately, there is a problem. One can try to hide it (as calculators attempt to do), but in the longer run that is going to be unsuccessful and even dangerous. Same as

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread Daniël Mantione
Op Mon, 29 Oct 2007, schreef L: Same as ansistring.. it can be dangerous to hide all the intricate details of a pchar/bytearray, which is what ansistring does. But ansistrings are really useful for 'every day' use. Wrong. A string can be represented alphadequate, as it is called; an

RE: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread Stephen Dickason
It's just one more funny thing one must realize, when comparing real numbers with some exact real constants. After this, I will try to never compare doubles directly, but using tricks like above. Because, in this digital world 1 + 0.4 - 0.4 1. In binary that is 0001 +

RE: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread Daniël Mantione
Op Mon, 29 Oct 2007, schreef Stephen Dickason: It's just one more funny thing one must realize, when comparing real numbers with some exact real constants. After this, I will try to never compare doubles directly, but using tricks like above. Because, in this digital world 1 + 0.4 -

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread Micha Nelissen
Stephen Dickason wrote: In binary that is 0001 + 0.0110011001100 - 0.0110011001100 because we hit recurring decimals a lot more in binary than decimal. I wonder why we don't have a standard format (maybe we do?) that factors in the remainder as part of the number also? It's

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread Florian Klaempfl
L schrieb: It's just one more funny thing one must realize, when comparing real numbers with some exact real constants. After this, I will try to never compare doubles directly, but using tricks like above. Because, in this digital world 1 + 0.4 - 0.4 1. My opinion: This is ludicrous.

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread Florian Klaempfl
Daniël Mantione schrieb: Op Mon, 29 Oct 2007, schreef L: Your Casio doesn't do comparisons. Just round to 10 digits before you compare and it'll work just as fine as on your Casio. Daniël And some off topic trivia: My casio says 10 + 2 digits near the model number. Does this mean it

Re: [fpc-pascal] Re: Why this evaluates on if wrong ? (GMP)

2007-10-29 Thread Tom Verhoeff
On Mon, Oct 29, 2007 at 06:36:11PM +0100, Micha Nelissen wrote: It's possible to create a type that stores the numerator and denominator, but then you would need to simplify to extract common factors on every calculation, otherwise it would quickly run out of range (Integer or whatever you

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread Daniël Mantione
Op Mon, 29 Oct 2007, schreef L: Same as ansistring.. it can be dangerous to hide all the intricate details of a pchar/bytearray, which is what ansistring does. But ansistrings are really useful for 'every day' use. Wrong. A string can be represented alphadequate, as it is called;

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread L
Same as ansistring.. it can be dangerous to hide all the intricate details of a pchar/bytearray, which is what ansistring does. But ansistrings are really useful for 'every day' use. Wrong. A string can be represented alphadequate, as it is called; an ansistring can handle any string you

Re: [fpc-pascal] Re: Why this evaluates on if wrong ? (GMP)

2007-10-29 Thread mm
Tom Verhoeff a écrit : In fact, the GMP (GNU Multiple Precision Arithmetic Library gmplib.org) offers this and more. Unfortunately, there does not seem to be a complete FreePascal interface for it. Maybe it is easy to adapt (if necessary?) the GNU Pascal interface for GMP

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread Joao Morais
Daniël Mantione wrote: And, as said before, no datastructure is adequate for storing a mathematical real number. Not even if you have infinite memory. Nope. If infinite memory was tangible, you would be able to store any real number. -- Joao Morais

Re: [fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-29 Thread mm
Joao Morais a écrit : Daniël Mantione wrote: And, as said before, no datastructure is adequate for storing a mathematical real number. Not even if you have infinite memory. Nope. If infinite memory was tangible, you would be able to store any real number. How many time would it take to

[fpc-pascal] Re: Why this evaluates on if wrong ?

2007-10-28 Thread Milan Marusinec
This behaviour normal and while annoying, it is simply how things work in the digital world, you will have to work around it. Daniël oh yes, this is one of the possible workarounds: function is_equal_dbl(a ,b : double ) : boolean; const epsilon = 1e-14; begin result:=Abs(a - b ) epsilon;