Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
nextafter.go52 linesDownload Raw Back to math
1// Copyright 2010 The Go Authors. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE file.4 5package math6 7// Nextafter32 returns the next representable float32 value after x towards y.8//9// Special cases are:10//11//	Nextafter32(x, x)   = x12//	Nextafter32(NaN, y) = NaN13//	Nextafter32(x, NaN) = NaN14func Nextafter32(x, y float32) (r float32) {15	switch {16	case IsNaN(float64(x)) || IsNaN(float64(y)): // special case17		r = float32(NaN())18	case x == y:19		r = x20	case x == 0:21		r = float32(Copysign(float64(Float32frombits(1)), float64(y)))22	case (y > x) == (x > 0):23		r = Float32frombits(Float32bits(x) + 1)24	default:25		r = Float32frombits(Float32bits(x) - 1)26	}27	return28}29 30// Nextafter returns the next representable float64 value after x towards y.31//32// Special cases are:33//34//	Nextafter(x, x)   = x35//	Nextafter(NaN, y) = NaN36//	Nextafter(x, NaN) = NaN37func Nextafter(x, y float64) (r float64) {38	switch {39	case IsNaN(x) || IsNaN(y): // special case40		r = NaN()41	case x == y:42		r = x43	case x == 0:44		r = Copysign(Float64frombits(1), y)45	case (y > x) == (x > 0):46		r = Float64frombits(Float64bits(x) + 1)47	default:48		r = Float64frombits(Float64bits(x) - 1)49	}50	return51}52 
codekingpro/portable-devtools · Team Ai