Re: benchmarks? java vs .net (sin and cos)

Discussion in 'Java' started by Mark Thornton, Jun 4, 2008.

  1. Jon Harrop wrote:
    > Razii wrote:
    >> Console.WriteLine(Math.Sin (1e15));
    >>
    >> 0.858272132476373 (C# with .NET)
    >> 0.8582727931702358355238863908484 (right answer)
    >>
    >> So C# doesn't get 15-17 digit accuracy of double for sin and cos.

    >
    > For double precision floating point your argument of 1e15 to sin has already
    > lost all precision because it is fourteen orders of magnitude outside the
    > primary domain of this trig function.
    >


    Sin and cos are defined for all real numbers. Sure Java is rather
    unusual in returning accurate results for all values of double (bar
    infinite and NaN). While many systems set the bar rather lower, one has
    to admire Java for raising it (and eventually delivering).

    Mark Thornton
     
    Mark Thornton, Jun 4, 2008
    #1
    1. Advertising

  2. Jon Harrop wrote:
    > Mark Thornton wrote:
    >> Jon Harrop wrote:
    >>> For double precision floating point your argument of 1e15 to sin has
    >>> already lost all precision because it is fourteen orders of magnitude
    >>> outside the primary domain of this trig function.

    >> Sin and cos are defined for all real numbers. Sure Java is rather
    >> unusual in returning accurate results for all values of double (bar
    >> infinite and NaN). While many systems set the bar rather lower, one has
    >> to admire Java for raising it (and eventually delivering).

    >
    > If Java were competitively performant here I would agree but this workaround
    > for legacy hardware is slowing a lot of code down for insignificant
    > practical benefit.
    >


    I'm not sure what you mean by legacy hardware as I have assumed that all
    x86 systems share the same 66 bit approximation of PI when doing
    'hardware' argument reduction for FSIN.

    As for the practical benefit I think the most troubling points are the
    values for sin in the vicinity of PI. It is just conceivable to me that
    this could make a practical difference.

    Mark Thornton
     
    Mark Thornton, Jun 4, 2008
    #2
    1. Advertising

  3. Jon Harrop wrote:
    > Mark Thornton wrote:
    >> Jon Harrop wrote:
    >>> If Java were competitively performant here I would agree but this
    >>> workaround for legacy hardware is slowing a lot of code down for
    >>> insignificant practical benefit.

    >> I'm not sure what you mean by legacy hardware as I have assumed that all
    >> x86 systems share the same 66 bit approximation of PI when doing
    >> 'hardware' argument reduction for FSIN.

    >
    > The modern 64-bit equivalents apparently do not. I have to run in a 32-bit
    > chroot to recreate this effect of using legacy hardware which is why I
    > hadn't noticed it before.
    >
    >> As for the practical benefit I think the most troubling points are the
    >> values for sin in the vicinity of PI. It is just conceivable to me that
    >> this could make a practical difference.

    >
    > I suspect people who care about such accuracy would not have chosen broken
    > hardware in the first place...
    >


    All too often those that care aren't the ones who choose the hardware.
    It just arrives ...

    I do think there is some merit in the fact that with Java we can expect
    to get the same answer regardless. It does make testing easier. When I
    first did numerical analysis there were still a number of variations of
    floating point in common use, which made constructing reliable and
    portable numerical software rather harder.

    Mark Thornton
     
    Mark Thornton, Jun 4, 2008
    #3
  4. Mark Thornton

    Arne Vajhøj Guest

    Jon Harrop wrote:
    > Razii wrote:
    >> On Wed, 04 Jun 2008 19:31:43 +0100, Jon Harrop <>
    >> wrote:
    >>> 64-bit or 32-bit Windows?

    >> 32-bit. I hope your next answer is not that 32-bit is legacy system.

    >
    > So you're running a 64-bit CPU in 32-bit mode.


    That is what most people do.

    32 bit Windows on a 64 bit capable Intel or AMD CPU.

    And therefore obviously what is most relevant to test.

    Arne
     
    Arne Vajhøj, Jun 9, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark Thornton
    Replies:
    3
    Views:
    494
    Arne Vajhøj
    Jun 9, 2008
  2. Patricia Shanahan

    Re: benchmarks? java vs .net (sin and cos)

    Patricia Shanahan, Jun 4, 2008, in forum: Java
    Replies:
    25
    Views:
    812
    Arne Vajhøj
    Jun 9, 2008
  3. Patricia Shanahan

    Re: benchmarks? java vs .net (sin and cos)

    Patricia Shanahan, Jun 4, 2008, in forum: C++
    Replies:
    24
    Views:
    841
    Arne Vajhøj
    Jun 9, 2008
  4. Jon Skeet [C# MVP]

    Re: benchmarks? java vs .net (sin and cos)

    Jon Skeet [C# MVP], Jun 4, 2008, in forum: Java
    Replies:
    33
    Views:
    862
    Arne Vajhøj
    Jun 17, 2008
  5. Jon Skeet [C# MVP]

    Re: benchmarks? java vs .net (sin and cos)

    Jon Skeet [C# MVP], Jun 4, 2008, in forum: C++
    Replies:
    33
    Views:
    947
    Arne Vajhøj
    Jun 17, 2008
Loading...

Share This Page