Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2018-01

Problem with fpc-3.0.4 and double

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

zeljko

Hi all,
In one of my applications I'm using someDouble1 someDouble2 for years, now got problem with fpc-3.0.4 (all previous fpc versions were ok (3.0.2, 3.0.0, 2.6.4, 2.6.2, 2.6.0...etc) + kylix + delphi7), so now must use IsSameValue(someDouble1,someDouble2) to get correct comparision of double types.

What exactly have been changed in fpc-3.0.4 with double types (or generally with floats) ? Do I have to check all of my code now and change comparisions of doubles to use IsSameValue() ?

Anyone boomed by such problem ?

P.S: Sorry for writing in lazarus list, don't have fpc list account...

zeljko

Reply by email

Ralf Quint
to zeljko
zeljko wrote 12 lines
Hi all, In one of my applications I'm using someDouble1 someDouble2 for years, now got problem with fpc-3.0.4 (all previous fpc versions were ok (3.0.2, 3.0.0, 2.6.4, 2.6.2, 2.6.0...etc) + kylix + delphi7), so now must use IsSameValue(someDouble1,someDouble2) to get correct comparision of double types. What exactly have been changed in fpc-3.0.4 with double types (or generally with floats) ?  Do I have to check all of my code now and change comparisions of doubles to use IsSameValue() ? Anyone boomed by such problem ?

Comparing any floating point value like this is pure luck when you claim that it worked in the past. In any programming language, unless maybe you are using one that by default utilizes BCD floats. Using binary floats, there are just too many values that can't be represented 100%, regardless of the length of the mantissa. https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems

Ralf

---
This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus

Reply by email

zeljko
to Ralf Quint
Ralf Quint wrote 7 lines
Comparing any floating point value like this is pure luck when you claim that it worked in the past. In any programming language, unless maybe you are using one that by default utilizes BCD floats. Using binary floats, there are just too many values that can't be represented 100%, regardless of the length of the mantissa. https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems

Thanks Ralf, I know what is floating point arithmetic, but something is changed between 3.0.2 and 3.0.4 and I want to know what it is.

zeljko

Reply by email

Marco van de Voort
to zeljko
zeljko wrote 6 lines
> Using binary floats, there are just too many values that can't be > represented 100%, regardless of the length of the mantissa. > https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems Thanks Ralf, I know what is floating point arithmetic, but something is changed between 3.0.2 and 3.0.4 and I want to know what it is.

It could be as simple as slightly different codegeneration that eliminates a temporary variable or adds it.

The x87 CPU calculates with 80-bits, but storing it into a double variable (e.g. a local variable on the stack) will round it to 64-bit double. This can cause small precision fluctuations, and, as with all regular float comparison issues, it is something of all times and all compilers.

Reply by email

zeljko
to Marco van de Voort
Marco van de Voort wrote 16 lines
On Wed, Jan 31, 2018 at 07:31:56PM +0100, zeljko via Lazarus wrote: >> Using binary floats, there are just too many values that can't be >> represented 100%, regardless of the length of the mantissa. >> https://en.wikipedia.org/wiki/Floating-point_arithmetic#Accuracy_problems > > Thanks Ralf, I know what is floating point arithmetic, but something is > changed between 3.0.2 and 3.0.4 and I want to know what it is. It could be as simple as slightly different codegeneration that eliminates a temporary variable or adds it. The x87 CPU calculates with 80-bits, but storing it into a double variable (e.g. a local variable on the stack) will round it to 64-bit double. This can cause small precision fluctuations, and, as with all regular float comparison issues, it is something of all times and all compilers.

Today I've found exact where's problem.
It's zeoslib 7.2.1 which uses fastcode (ZFastCode) implementation and results of StrToFloatDef() are bit different than results which is given by fpc's StrToFloatDef().
Changed code to use fpc functions and everything is correct now :)

Thanks for your time ppl

zeljko

Reply by email