tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 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