modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/floatcmp.go (about) 1 // run 2 3 // Copyright 2009 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 // Test floating-point comparison involving NaN. 8 9 package main 10 11 import "math" 12 13 type floatTest struct { 14 name string 15 expr bool 16 want bool 17 } 18 19 var nan float64 = math.NaN() 20 var f float64 = 1 21 22 var tests = []floatTest{ 23 floatTest{"nan == nan", nan == nan, false}, 24 floatTest{"nan != nan", nan != nan, true}, 25 floatTest{"nan < nan", nan < nan, false}, 26 floatTest{"nan > nan", nan > nan, false}, 27 floatTest{"nan <= nan", nan <= nan, false}, 28 floatTest{"nan >= nan", nan >= nan, false}, 29 floatTest{"f == nan", f == nan, false}, 30 floatTest{"f != nan", f != nan, true}, 31 floatTest{"f < nan", f < nan, false}, 32 floatTest{"f > nan", f > nan, false}, 33 floatTest{"f <= nan", f <= nan, false}, 34 floatTest{"f >= nan", f >= nan, false}, 35 floatTest{"nan == f", nan == f, false}, 36 floatTest{"nan != f", nan != f, true}, 37 floatTest{"nan < f", nan < f, false}, 38 floatTest{"nan > f", nan > f, false}, 39 floatTest{"nan <= f", nan <= f, false}, 40 floatTest{"nan >= f", nan >= f, false}, 41 floatTest{"!(nan == nan)", !(nan == nan), true}, 42 floatTest{"!(nan != nan)", !(nan != nan), false}, 43 floatTest{"!(nan < nan)", !(nan < nan), true}, 44 floatTest{"!(nan > nan)", !(nan > nan), true}, 45 floatTest{"!(nan <= nan)", !(nan <= nan), true}, 46 floatTest{"!(nan >= nan)", !(nan >= nan), true}, 47 floatTest{"!(f == nan)", !(f == nan), true}, 48 floatTest{"!(f != nan)", !(f != nan), false}, 49 floatTest{"!(f < nan)", !(f < nan), true}, 50 floatTest{"!(f > nan)", !(f > nan), true}, 51 floatTest{"!(f <= nan)", !(f <= nan), true}, 52 floatTest{"!(f >= nan)", !(f >= nan), true}, 53 floatTest{"!(nan == f)", !(nan == f), true}, 54 floatTest{"!(nan != f)", !(nan != f), false}, 55 floatTest{"!(nan < f)", !(nan < f), true}, 56 floatTest{"!(nan > f)", !(nan > f), true}, 57 floatTest{"!(nan <= f)", !(nan <= f), true}, 58 floatTest{"!(nan >= f)", !(nan >= f), true}, 59 floatTest{"!!(nan == nan)", !!(nan == nan), false}, 60 floatTest{"!!(nan != nan)", !!(nan != nan), true}, 61 floatTest{"!!(nan < nan)", !!(nan < nan), false}, 62 floatTest{"!!(nan > nan)", !!(nan > nan), false}, 63 floatTest{"!!(nan <= nan)", !!(nan <= nan), false}, 64 floatTest{"!!(nan >= nan)", !!(nan >= nan), false}, 65 floatTest{"!!(f == nan)", !!(f == nan), false}, 66 floatTest{"!!(f != nan)", !!(f != nan), true}, 67 floatTest{"!!(f < nan)", !!(f < nan), false}, 68 floatTest{"!!(f > nan)", !!(f > nan), false}, 69 floatTest{"!!(f <= nan)", !!(f <= nan), false}, 70 floatTest{"!!(f >= nan)", !!(f >= nan), false}, 71 floatTest{"!!(nan == f)", !!(nan == f), false}, 72 floatTest{"!!(nan != f)", !!(nan != f), true}, 73 floatTest{"!!(nan < f)", !!(nan < f), false}, 74 floatTest{"!!(nan > f)", !!(nan > f), false}, 75 floatTest{"!!(nan <= f)", !!(nan <= f), false}, 76 floatTest{"!!(nan >= f)", !!(nan >= f), false}, 77 } 78 79 func main() { 80 bad := false 81 for _, t := range tests { 82 if t.expr != t.want { 83 if !bad { 84 bad = true 85 println("BUG: floatcmp") 86 } 87 println(t.name, "=", t.expr, "want", t.want) 88 } 89 } 90 if bad { 91 panic("floatcmp failed") 92 } 93 }