This is not something that I've thought about before, but the behaviour
of math.Max when only one of its arguments is NaN does not agree with
the C convention or the IEEE-754 standard behaviour for max (5.3.1 p19
"maxNum(x, y) is the canonicalized number y if x<y, x if y<x, the
canonicalized number if one operand is a number and the other a quiet
NaN.").

Does anyone know the reason for this? (Looking through other languages,
the situation in general seems to be a mess).

e.g. in C

~ $ cat n.c
#include <math.h>
#include <stdio.h>

void main() {
        printf("%f\n", fmax(1, nan("")));
}
~ $ gcc -o a.out n.c
~ $ ./a.out
1.000000

and in Go

~ $ cat n.go
package main

import (
        "fmt"
        "math"
)

func main() {
        fmt.Println(math.Max(1, math.NaN()))
}
~ $ go run n.go
NaN


-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/847aef7e13affb06ad098f1aafbd6b4ad1be7ae3.camel%40kortschak.io.

Reply via email to