MikeMcl / decimal.js

An arbitrary-precision Decimal type for JavaScript
http://mikemcl.github.io/decimal.js
MIT License
6.35k stars 480 forks source link

Degrees for trigonometric functions? #193

Open soshimee opened 2 years ago

soshimee commented 2 years ago

I need degrees for what I am doing, and radians won't work. Converting from radians to degrees with high accuracy doesn't seem to possible.

jrus commented 2 years ago

I’m not sure if PI is exposed in the API,† but you can get one from e.g. Decimal.atan(1).times(4). Once you have a representation of π you can convert to/from degrees by multiplying/dividing by π/180

†: If not, it probably should be, https://github.com/MikeMcl/decimal.js/blob/master/decimal.js#L32 defines it to 1025 digits and https://github.com/MikeMcl/decimal.js/blob/master/decimal.js#L3168 is a helper function that makes a Decimal out of it.

MikeMcl commented 2 years ago

@soshimee

What makes you think it is not possible?

It is straightforward but I am not inclined to do the work for you.

Decimal.set({ precision: 100 });
pi = Decimal.acos(-1);