I just ran this code on my pc:
package main
import (
"fmt"
"math"
)
func main() {
const ali = 4e20
fmt.Println(math.Sin(ali))
}
and got this result:
1.3471173831553043e+258
Why Sin result goes more than 1?
Python and some other languages have correct result
The math package in Go contains entirely of many math functions that can be used to do different things. Here are the main math functions that are used frequently. The most common math functions are as follows.
Go language provides inbuilt support for basic constants and mathematical functions to perform operations on the numbers with the help of the math package. This function is used to return the absolute value of the specified number.
The math package contains many common functions that otherwise if implemented by the user may prove to be inefficient. 1. The Abs function The Abs function produces the absolute value of a float64 number. 2. The trigonometric functions The trigonometric functions are sin, cos, tan, their inverse and hyperbolic functions. 3. The log function
To do modulus math with float64 data types, you’ll use the Mod function from the math package: In Go, as in mathematics, we need to keep in mind that operators will be evaluated in order of precedence, not from left to right or right to left.
It seems like it's just an issue with the implementation, if the input is more than 2**49 it causes issues. Found a really old issue here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With