extended type equality lazarus / 62-General ---------------------------------------------------------------------- littlepaul476 · 2018-11-21 09:22 Can someone explain to me, why this ended with ? Double or Real alternatives are . Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var i,j: extended;begin  i:=23500.0*0.032;  j:=752.0;  if i=j then      else    ;end; Lazarus 1.8.4. FPC 3.0.4, Win32 ---------------------------------------------------------------------- marcov · 2018-11-21 09:28 Floating point math is not exact.  Extended on 32-bit x86 has more precision, so the deviation from the exact value suddenly fits extended. If you print i you get 7.51999999999999999944E+0002 There is a lot of information about comparing floating point values on the internet, I suggest you read it for a background. https://floating-point-gui.de/errors/comparison/ https://bitbashing.io/comparing-floats.html The common trick is to compare with a small deviation (if abs(x-y)B) then    Result:=((A-B)<=Epsilon)  else    Result:=((B-A)<=Epsilon);end; ---------------------------------------------------------------------- srvaldez · 2018-11-21 12:38 I played with this for a while changing the expression i:=23500.0*0.032; to i:=23500.0*32/1000; made it work I thought that casting the literal constant to extended would work, but it made no difference. ---------------------------------------------------------------------- PascalDragon · 2018-11-21 13:40 Simply don't assume that two floating point values are equal (except when checking for special values like 0, +/- Infinity and NaN). Everything else will only lead to problems sooner or later. ---------------------------------------------------------------------- Gammatester · 2018-11-21 14:35 Floating point arithmetic works by rounding the true result to the next representable floating point number (using the selected precision and rounding mode). With double precision you have Code: [Select]0.032 -> 0.0320000000000000006661338147750939242541790008544921875 0.032*23500 -> 752.00000000000001565414464721470721997320652008056640625 The last number is rounded to 752 and with FPC304/Win7 you really get OK! OTH, for extended precision you get Code: [Select]0.032 -> 0.03199999999999999999867185233870525706834087031893432140350341796875 0.032*23500 -> 751.999999999999999968788529959573541106010452494956552 982330322265625The last number is rounded to 751.999999999999999944488848768742172978818416595458984375, and therefore you get NOT OK. Your expression 23500.0*32/1000 works, because all numbers are (representable as) integers and so the result must be an integer.