🌐
W3Schools
w3schools.com › java › java_math.asp
Java Math
The Java Math class has many methods that allows you to perform mathematical tasks on numbers.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › lang › Math.html
Math (Java Platform SE 8 )
October 20, 2025 - Java™ Platform Standard Ed. 8 ... The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
Discussions

Precision of Java math functions - Stack Overflow
I was coding some floating point intensive algorithm and couldn't get the outcomes as expected (actually I am trying to migrate my old C program into Java). Still a newbie in Java, 2 months old! ;)... More on stackoverflow.com
🌐 stackoverflow.com
eclipse - How to get the rest of java Math funtions? - Stack Overflow
There should be no problem using any of these functions, so we need to see what you are doing to get some idea of what the problem is. ... This was closed by people who are unaware of Codename One which was tagged correctly. The correct answer is use MathUtil for extra APIs ... Looks like codename1 overrides some of the java ... More on stackoverflow.com
🌐 stackoverflow.com
How precise is Java's Math class?
The key thing to note is that BigDecimal is decimal. That is, it stores a precise representation of decimal (base-10) numbers. That is, the number is represented as a sum of powers of ten. float and double are binary (IEEE 754). That is, the number is represented as a sum of powers of two. Thus, when you translate a decimal fraction into a binary fraction, you'll end up with errors, because some decimal fractions cannot be represented exactly as binary fractions (within a given precision). These errors add up. The Math functions are intrinsics. They map directly to native routines, which operate on IEEE 754 floating point numbers. Obviously, most floating point units on processors work on IEEE floats (although, I think some older processors could do BCD math). BigDecimal is implemented purely in Java, trading performance for precision, and any math library operating on BigDecimal would have to reimplement all of those math operations in Java, similarly trading performance for precision, to a greater degree. Whether you choose float of BigDecimal depends on your goals. With money, generally the goal is precision, because of the financial consequences of errors in accounting calculations. But, in scientific and engineering application, the goal is reasonable approximation within an error range. I don't think with Black-Sholes you're looking for precision, but approximation. Thus, it is perfectly fine to use float as long as you arrange your calculations to control the error range. Poor arrangement of floating point calculations can significantly widen the error range, resulting wildly deviating results. For this reason, there are books like Numerical Computing with IEEE Floating Point Arithmetic which show you how to arrange floating point calculations to maintain accuracy within a desired error range. EDITED: I don't write good. More on reddit.com
🌐 r/java
84
68
June 16, 2024
Java math libraries?
Apache Math has a polynomial fitter. It also has a linear solver and lots of other useful bits. I haven't used a symbolic math solver in Java. It's not quite the same, but I did use Z3 with Java this year, there is z3-turnkey that provides a helpful Maven dependency for that. More on reddit.com
🌐 r/adventofcode
4
8
December 26, 2023
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-math-class
Java Math Class - GeeksforGeeks
July 23, 2025 - Java.lang.Math Class methods help to perform numeric operations like square, square root, cube, cube root, exponential and trigonometric operations.
🌐
FavTutor
favtutor.com › blogs › java-math-class
Math Class in Java & Methods (with Examples)
October 9, 2023 - The Math class is a part of the java.lang package, which is automatically imported into every Java program. This means that you can access the Math class without explicitly importing it. The Math class provides a wide range of mathematical functions and constants that are useful for various calculations.
🌐
Baeldung
baeldung.com › home › java › java numbers › a guide to the java math class
A Guide to the Java Math Class | Baeldung
January 8, 2024 - The first set of methods we’ll cover are the basic math functions such as the absolute value, the square root, the maximum or the minimum between two values.
🌐
W3Schools
w3schools.com › java › java_ref_math.asp
Java Math Reference
The Java Math class has many methods that allows you to perform mathematical tasks on numbers.
🌐
Jenkov
jenkov.com › tutorials › java › math-operators-and-math-class.html
Java Math Operators and Math Class
The java.lang.Math contains a set of basic math functions for obtaining the absolute value, highest and lowest of two values, rounding of values, random values etc.
Find elsewhere
🌐
Medium
medium.com › @AlexanderObregon › beginners-guide-to-java-math-21edc9cc1ee0
Java Math Guide for Beginners | Medium
March 9, 2024 - The Math class is part of the java.lang ... for performing advanced mathematical calculations, including exponential, logarithmic, trigonometric functions, and more....
🌐
Programiz
programiz.com › java-programming › library › math
Java Math Methods | Programiz
In this reference page, you will find all the math methods available in Java. For example, if you need to get the square root of a number, use the sqrt() method. returns the absolute value of a number · returns the arc cosine of the specified value · adds the specified numbers and returns it · returns the arc sine of the specified argument · returns the inverse tangent function of a value ·
🌐
Wikibooks
en.wikibooks.org › wiki › Java_Programming › Mathematical_functions
Mathematical functions - Wikibooks, open books for an open world
The java.lang.Math class allows the use of many common mathematical functions that can be used while creating programs.
Top answer
1 of 5
7

float has about 7.2 significative decimal digits.
double has about 15.9 significative decimal digits.

Your examples have the same 16 first significative decimal digits. This means that both pieces of code are getting exactly the same binary result. Assuming that your C compiler uses the same IEEE standard for 64 bit floats as java which is likely.

The difference you see after those 16 digits does not come from the way the math operation is performed and does not come from rounding error but from the way the different print functions deal with converting from binary double to decimal text.

2 of 5
3

The quickest way to get a correct answer is to use Wolfram alpha pi^10 this give the value of 93648.04747608302097371669018491934563599815727551469412705244 more digits could probably be obtained if needed. We see the cygwin C code is only correct to 15 digits

93648.0474760829820297658443   C 
93648.04747608298              Java
93648.04747608302097371669018491934563599815727551469412705244
93648.047476082984468098606014523496270846023460034084392213341627

so you have exactly the same precision in both systems. You would expect to get same precision as both will likely use the IEEE 754 double precision floating point. You could say that java answer is better as it is not giving a false sense of accuracy by displaying more digits.

Unless you are specifically interested in calculating digits of pi or other number theory related task 16 digit accuracy will satisfy your needs. I've never seen an application where BigDecimal has proved to be useful and it requires a lot of work to get right.

A BigDecimal solution would be

    MathContext mc = MathContext.DECIMAL128;
    BigDecimal pi = new BigDecimal("3.141592653589793238462643383279503",mc);
    BigDecimal res = pi.pow(10, mc);
    out.println(pi);
    out.println(res);

This uses a specific MathContext, the most accurate pre-defined one. If the numbers are approximate, as pi is, then its better to specify a MathContext. The only time you really want to use BigDecimal without a MathContext is if your values are exact, I not come across a time when you want to use this.

We use the string constructor with a value obtained from Wolfram alpha and the MathContext to fix the precision. We also use the same MathContext when calculating the power. The result of this is

3.141592653589793238462643383279503
93648.04747608302097371669018491938

if we compare this with the actual result which ends in 934 we see the result has an error in the last digit. Generally you expect most mathematics algorithms to be correct to within one unit of the last place, pow is a bit worse with a 2 ulp error. Using a MathContext mean we do not display spurious incorrect digits.

🌐
Android Developers
developer.android.com › api reference › math
Math | API reference | Android Developers
Skip to main content · English · Deutsch · Español – América Latina · Français · Indonesia · Polski · Português – Brasil · Tiếng Việt · 中文 – 简体
🌐
Tutorialspoint
tutorialspoint.com › home › java › java math class
Java Math Class Overview
September 1, 2008 - The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
🌐
Oracle
docs.oracle.com › en › java › javase › 21 › docs › api › java.base › java › lang › Math.html
Math (Java SE 21 & JDK 21)
January 20, 2026 - java.lang.Math · public final class Math extends Object · The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. Unlike some of the numeric methods of class StrictMath, all implementations ...
🌐
Oxford University
mathcenter.oxford.emory.edu › site › cs170 › mathClass
Commonly Used Methods of the Math Class
The operators +, -, *, /, and % give us a way to add, subtract, multiply, divide, and "mod" values together in java, but having to implement some of the more sophisticated functions of mathematics (like the square root or sine functions) with only these operators would be challenging indeed!
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.lang.math
Math Class (Java.Lang) | Microsoft Learn
The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions. [Android.Runtime.Register("java/lang/Math", DoNotGenerateAcw=true)] public sealed ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › math-class-methods-java-examples-set-2
Math class methods in Java with Examples | Set 2 - GeeksforGeeks
July 23, 2025 - IEEEremainder() : java.math.IEEERemainder(double d1, double d2) method returns the remainder value by applying remainder operation on two arguments w.r.t IEEE 754 standard. Remainder value = d1 - d2 * n where, n = closest exact value of d1/d2 ·
🌐
Skeoop
skeoop.github.io › java-basics › 06-Math-Functions.pdf pdf
06-Math-Functions.pdf
Math.max( 3, 1.25 ) ? Functions and Data Types · Java promotes one of the arguments until it finds a · matching function prototype. Example · Promotion · Then Call · Math.max( 2, 10.0F ) 2 to 2.0F · max(2F, 10F) Math.max(-1, -4L ) -1 to -1L · max(-1L, -4L) Math.max( 3, 2.236 ) 3 to 3.0 ·