Kevin Simonson

Ranch Hand

Posts: 223

2

posted 3 years ago

The {Math} class has methods {cos()}, {sin()}, {tan()}, {acos()}, {asin()}, {atan()}, {log()}, and {pow()}. I'm trying to write a Java class that implements these functions for {BigDecimal}s. There's a Taylor series that converges pretty quickly for the cosine and the sine, but I don't know of any as quick way to calculate any of the other six functions. To calculate the tangent does {Math} just calculate the sine and cosine and divide the former by the latter? And does anyone know how {Math} calculates the latter six functions so that I can implement those calculations for {BigDecimal}s?

Kevin S

Kevin S

posted 3 years ago

the JDK install gives you the source code for pretty much everything. I think it comes as src.zip, which you can open and look at to your heart's content.

-edit- I

-edit 2 - well...i looked...at least at the sin function...it doesn't actually help:

-edit- I

*think*...-edit 2 - well...i looked...at least at the sin function...it doesn't actually help:

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

posted 3 years ago

Which I did... the code for Math.tan just calls StrictMath.tan; and the code for StrictMath.tan (and all the other methods too) is declared "native". And that's it for the Java code.

I've heard that the code base for the JVM is open-source now, but whether that applies to the various native code bases I don't know.

I've heard that the code base for the JVM is open-source now, but whether that applies to the various native code bases I don't know.

posted 3 years ago

I don't know whether or not is still is but for a long time when it comes to approximations for just about any functions you can think of the Bible used to be "Handbook of Mathematical Functions" by Abramowitz and Stegun . It contains a whole section on the elementary transcendental functions giving numerical approximations, series and continued fractions. I know that there is now a PDF version of Abramowitz and Stegun floating around so you probably don't have to buy it but I purchased mine in 1971 and it was £5 very very well spent.

Consider Paul's rocket mass heater. |