Jump to page: 1 2
Thread overview
[Issue 13548] wrong sqrt
[Issue 13548] wrong FP comparison
Feb 08, 2015
yebblies
[Issue 13548] wrong CTFE sort
[Issue 13548] wrong CTFE sqrt
Aug 29, 2020
Walter Bright
Aug 31, 2020
Walter Bright
Sep 01, 2020
Walter Bright
Mar 25, 2022
RazvanN
September 27, 2014
https://issues.dlang.org/show_bug.cgi?id=13548

Илья Ярошенко <ilyayaroshenko@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code

--
October 02, 2014
https://issues.dlang.org/show_bug.cgi?id=13548

hsteoh@quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh@quickfur.ath.cx

--
February 08, 2015
https://issues.dlang.org/show_bug.cgi?id=13548

yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com

--- Comment #1 from yebblies <yebblies@gmail.com> ---
My guess is that this is a similar bug to issue 13474, where ad is truncated by saving it to the stack then reloading it, while cd is kept in a register after being returned with >double precision.

--
February 14, 2015
https://issues.dlang.org/show_bug.cgi?id=13548

--- Comment #2 from Илья Ярошенко <ilyayaroshenko@gmail.com> ---
Probably this is reduced example for FreeBSD_32 and Win32:

----
double two = 2.0;
assert(sqrt(two) == sort(2.0));
----

--
February 14, 2015
https://issues.dlang.org/show_bug.cgi?id=13548

Илья Ярошенко <ilyayaroshenko@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86_64                      |All
            Summary|wrong FP comparison         |wrong CTFE sort
                 OS|Windows                     |All

--
February 14, 2015
https://issues.dlang.org/show_bug.cgi?id=13548

Илья Ярошенко <ilyayaroshenko@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|wrong CTFE sort             |wrong CTFE sqrt

--
February 20, 2015
https://issues.dlang.org/show_bug.cgi?id=13548

Илья Ярошенко <ilyayaroshenko@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|wrong CTFE sqrt             |wrong sqrt

--
August 29, 2020
https://issues.dlang.org/show_bug.cgi?id=13548

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |backend
                 CC|                            |bugzilla@digitalmars.com

--
August 31, 2020
https://issues.dlang.org/show_bug.cgi?id=13548

--- Comment #3 from Walter Bright <bugzilla@digitalmars.com> ---
Code:

  import core.stdc.math;
  void main() {
    double two = 2.0;
    assert(sqrt(two) == sqrt(2.0));
  }

Generates for main():

        enter   014h,0
        fld     qword ptr FLAT:CONST[00h]
        fstp    qword ptr -8[EBP]
        push    dword ptr -4[EBP]
        push    dword ptr -8[EBP]
        call    near ptr _sqrt
        add     ESP,8
        push    dword ptr FLAT:CONST[04h]
        push    dword ptr FLAT:CONST[00h]
        fstp    qword ptr -014h[EBP]
        call    near ptr _sqrt
        add     ESP,8
        fld     qword ptr -014h[EBP]
        fxch    ST(1)
        fucompp ST(1),ST
        fstsw   AX
        sahf
        jp      L40
        je      L4D
L40:    push    6
        mov     EAX,offset FLAT:___a7_74657374322e64
        push    EAX
        call    near ptr __d_assertp
L4D:    xor     EAX,EAX
        leave
        ret

Both calls to sqrt() produce the same result in ST0. But the first one stores and reloads it as a double, thus causing a round-to-double operation. The second does not, so they compare unequal. yebblies is right.

I'm not sure what the right fix would be. I could change sqrt() in DMC's runtime library to store/load the value it returns, but that wouldn't fix things for FreeBSD32.

On Win64 there isn't a problem because the sqrt() result is returned in XMM0
rather than ST0.

--
September 01, 2020
https://issues.dlang.org/show_bug.cgi?id=13548

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
I fixed DMC's sqrt to round to double.


https://github.com/DigitalMars/dmc/commit/29d49d5527fcb3e92f0b6f8620eb1bd9e0de1a14

Not much I can do about FreeBSD32.

--
« First   ‹ Prev
1 2