Hello rsc@golang.org, golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
13 years, 8 months ago
(2011-12-09 22:12:55 UTC)
#1
I'm sorry, but I take back what I said. I tested the C library on ...
13 years, 8 months ago
(2011-12-09 22:42:51 UTC)
#2
I'm sorry, but I take back what I said.
I tested the C library on my machine,
and it has nextafter(0, -1) == -0.
We should probably match that.
It may not be worth it, but if you take the
floating point bits as an int64, and then do:
if negative { xor with 1<<63 - 1 }
then I think that maps all the non-NaN
floating-point values to int64 in a way
that preserves the ordering (the old float64
order is now the order of the int64).
If that's right, then the function can
simplify to
if x != x || y != y {
return NaN()
}
ix := int64(Float64bits(x))
ix ^= int64(uint64(ix>>63)>>1)
iy := int64(Float64bits(y))
iy ^= int64(uint64(iy>>63)>>1)
if ix < iy {
ix++
} else if ix > iy {
ix--
}
ix ^= int64(uint64(ix>>63)>>1)
return Float64frombits(uint64(ix))
Or it might not.
Russ
On Fri, Dec 9, 2011 at 17:42, Russ Cox <rsc@golang.org> wrote: > I'm sorry, but ...
13 years, 8 months ago
(2011-12-09 22:45:18 UTC)
#3
On Fri, Dec 9, 2011 at 17:42, Russ Cox <rsc@golang.org> wrote:
> I'm sorry, but I take back what I said.
Never mind: the current code is fine.
My C program was using %f and showing -0.00000
but that's not really -0. Changing it to say %.17g
shows the number we expected.
$ cat x.c
#include <stdio.h>
#include <math.h>
int
main(void)
{
printf("%.17g\n", nextafter(0, -1));
}
$ a.out
-4.9406564584124654e-324
$
This CL is fine as is, except please add this as a test case.
Russ
Oops, ignore the 7:39 PM CL. I'll change it back. On Fri, Dec 9, 2011 ...
13 years, 8 months ago
(2011-12-10 00:40:19 UTC)
#5
Oops, ignore the 7:39 PM CL. I'll change it back.
On Fri, Dec 9, 2011 at 5:45 PM, Russ Cox <rsc@golang.org> wrote:
> On Fri, Dec 9, 2011 at 17:42, Russ Cox <rsc@golang.org> wrote:
>> I'm sorry, but I take back what I said.
>
> Never mind: the current code is fine.
> My C program was using %f and showing -0.00000
> but that's not really -0. Changing it to say %.17g
> shows the number we expected.
>
> $ cat x.c
> #include <stdio.h>
> #include <math.h>
>
> int
> main(void)
> {
> printf("%.17g\n", nextafter(0, -1));
> }
> $ a.out
> -4.9406564584124654e-324
> $
>
> This CL is fine as is, except please add this as a test case.
>
> Russ
Issue 5467060: code review 5467060: math: fix special cases in Nextafter
(Closed)
Created 13 years, 8 months ago by Charlie Dorian
Modified 13 years, 8 months ago
Reviewers:
Base URL:
Comments: 0