The following question:
What is/are the return value(s) of the following function
MySqrt
forf
equals to -2 ?func MySqrt(f float64)(float64, error) { //return an error as second parameter if invalid input if (f < 0) { return float64(math.NaN()), errors.New("I won't be able to do a sqrt of negative number!") } //otherwise use default square root function return math.Sqrt(f), nil}
has a correct answer of Both B and C
; However, when running the same exact code snippet:
package main
import (
"fmt"
"math"
"errors"
)
func MySqrt(f float64)(float64, error) {
//return an error as second parameter if invalid input
if (f < 0) {
return float64(math.NaN()), errors.New("I won't be able to do a sqrt of negative number!")
}
//otherwise use default square root function
return math.Sqrt(f), nil
}
func main() {
fmt.Println(MySqrt(-2))
}
it prints
NaN I won’t be able to do a sqrt of negative number!
Is there’s something I’m not getting ?