Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Safe-addition/Go/safe-addition.go
Normal file
30
Task/Safe-addition/Go/safe-addition.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math"
|
||||
)
|
||||
|
||||
// type requested by task
|
||||
type interval struct {
|
||||
lower, upper float64
|
||||
}
|
||||
|
||||
// a constructor
|
||||
func stepAway(x float64) interval {
|
||||
return interval {
|
||||
math.Nextafter(x, math.Inf(-1)),
|
||||
math.Nextafter(x, math.Inf(1))}
|
||||
}
|
||||
|
||||
// function requested by task
|
||||
func safeAdd(a, b float64) interval {
|
||||
return stepAway(a + b)
|
||||
|
||||
}
|
||||
|
||||
// example
|
||||
func main() {
|
||||
a, b := 1.2, .03
|
||||
fmt.Println(a, b, safeAdd(a, b))
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue