Bug in Math functions Sqrt and Double in LAMW lazarus / 43-Android ---------------------------------------------------------------------- neuro · 2021-05-31 13:39 How to fix bug in Math functions Sqrt and Double in LAMW? 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 jTextView1.Text := FloatToStr(Sqrt(36)); // <<-- produces correct answerjTextView2.Text := FloatToStr(Sqrt(Double(36))); // <<-- produces wrong answer, produces very small Double number which is very close to zero. Both lines should produce the same result. In Windows, Linux, macOS it produces correct answer. In Android it fails. How to fix this bug? ---------------------------------------------------------------------- wp · 2021-05-31 16:11 Quote from: neuro on May 31, 2021, 03:39:21 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i Double(36)I would not use this code at all because I never know whether this converts the integer 36 to a double value, or casts the bit presentation of the integer to the bit presentation of a double. Why don't you simply type the old-fashioned "36.0"? 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 jTextView2.Text := FloatToStr(Sqrt(36.0)); ---------------------------------------------------------------------- AlexTP · 2021-05-31 16:39 QuoteI never know whether this converts the integer 36 to a double valuePerson said that it produced the correct result on several OS'es. ---------------------------------------------------------------------- MarkMLl · 2021-05-31 16:47 Quote from: Alextp on May 31, 2021, 06:39:31 pmQuoteI never know whether this converts the integer 36 to a double valuePerson said that it produced the correct result on several OS'es. Without specifying precisely which OSes, their wordsize or endianness, or showing the results. It's not beyond the bounds of possibility for Sqrt(36.0) to be computed as 8.00000001 MarkMLl ---------------------------------------------------------------------- Thaddy · 2021-05-31 16:57 Correct, but I would add that hardcast should be avoived. I suspect that contributes to the issue. ---------------------------------------------------------------------- engkin · 2021-05-31 17:56 It is a bug. Similar to this one. Related thread. Quoting Macro's comment from the bug report: QuoteUsually the rules are hard cast when the same size, and conversion otherwise. But the problem here is probably the size of literal, and/or rules for typeconversion that can change the size of the literal.