gitee.com/quant1x/num@v0.3.2/math32/nextafter.go (about) 1 // Copyright 2010 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package math32 6 7 // Nextafter returns the next representable float32 value after x towards y. 8 // 9 // Special cases are: 10 // 11 // Nextafter32(x, x) = x 12 // Nextafter32(NaN, y) = NaN 13 // Nextafter32(x, NaN) = NaN 14 func Nextafter(x, y float32) (r float32) { 15 switch { 16 case IsNaN(x) || IsNaN(y): // special case 17 r = float32(NaN()) 18 case x == y: 19 r = x 20 case x == 0: 21 r = float32(Copysign(Float32frombits(1), y)) 22 case (y > x) == (x > 0): 23 r = Float32frombits(Float32bits(x) + 1) 24 default: 25 r = Float32frombits(Float32bits(x) - 1) 26 } 27 return 28 }