...
Run Format

Source file src/math/nextafter.go

     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 math
     6	
     7	// Nextafter32 returns the next representable float32 value after x towards y.
     8	// Special cases:
     9	//	Nextafter32(x, x)   = x
    10	//      Nextafter32(NaN, y) = NaN
    11	//      Nextafter32(x, NaN) = NaN
    12	func Nextafter32(x, y float32) (r float32) {
    13		switch {
    14		case IsNaN(float64(x)) || IsNaN(float64(y)): // special case
    15			r = float32(NaN())
    16		case x == y:
    17			r = x
    18		case x == 0:
    19			r = float32(Copysign(float64(Float32frombits(1)), float64(y)))
    20		case (y > x) == (x > 0):
    21			r = Float32frombits(Float32bits(x) + 1)
    22		default:
    23			r = Float32frombits(Float32bits(x) - 1)
    24		}
    25		return
    26	}
    27	
    28	// Nextafter returns the next representable float64 value after x towards y.
    29	// Special cases:
    30	//	Nextafter64(x, x)   = x
    31	//      Nextafter64(NaN, y) = NaN
    32	//      Nextafter64(x, NaN) = NaN
    33	func Nextafter(x, y float64) (r float64) {
    34		switch {
    35		case IsNaN(x) || IsNaN(y): // special case
    36			r = NaN()
    37		case x == y:
    38			r = x
    39		case x == 0:
    40			r = Copysign(Float64frombits(1), y)
    41		case (y > x) == (x > 0):
    42			r = Float64frombits(Float64bits(x) + 1)
    43		default:
    44			r = Float64frombits(Float64bits(x) - 1)
    45		}
    46		return
    47	}
    48	

View as plain text