user3143691
user3143691

Reputation: 1553

Math function returns wrong value

I have the following calculations:

let sinX = sin(150.0) //returns -0,71487
let cosY = cos(150.0) // returns 0,699250

But the real values for sinX = 0,5 and for cosY = -0,86.

Does anybody know where is the error?

Upvotes: 2

Views: 387

Answers (2)

Sigmabooma
Sigmabooma

Reputation: 43

And are you sure the sin & cos methods haven't been redefined by creating or overriding the default methods. That happens in programming. If so, you might want to re-check your operation.

Upvotes: 1

Roman Pustylnikov
Roman Pustylnikov

Reputation: 1932

The calculation is correct. However sin and cos take their param in radians, not degrees.

In calculus and most other branches of mathematics beyond practical geometry, angles are universally measured in radians. One radian is equal to 180/π degrees.

To convert from radians to degrees, multiply by 180/π.

https://en.wikipedia.org/wiki/Radian

Upvotes: 6

Related Questions