Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the Math class of Java mathematical function

Shulou Source: shulou.com Published: 2022-06-01 13:34:30 09月16日 Update

This article mainly explains the "Java mathematical function Math class how to use", the article explains the content is simple and clear, easy to learn and understand, the following please follow the editor's train of thought slowly in depth, together to study and learn "Java mathematical function Math class how to use" it!

1. Abs (x) returns the absolute value of the number x.

Math.abs (11.3); / / 11.3Math.abs (- 11.3)

2. CopySign (xQuery y) returns the value of the first parameter and the symbol of the second parameter.

Math.copySign (1.25,11.3); / /-1.25Math.copySign (- 11.3,1.25); / / 11.3

3. Signum (x) returns 1.0 if x is greater than 0,-1.0 if less than 0, and 0.0 if equal to 0

Math.signum; / / 1.0Math.signum (- 10.3); / /-1.0Math.signum (0); / / 0.0

4. Exp (x) returns the x power of e.

5. Expm1 (x) returns the x power of e-1.

6. Ceil (x) returns the nearest integer greater than x.

Math.ceil; / / 16Math.ceil (- 15.5); / /-15

7. Floor (x) returns the nearest integer less than x.

Math.floor; / / 15Math.floor (- 15.5); / /-16

8. Hypot (xQuery y) returns the quadratic root of x ²+ y ².

Math.hypot (x, y); / / √ (x ²+ y ²) Math.hypot (3,4); / / 5

9. Sqrt (x) returns the quadratic root of x.

Math.sqrt (9); / / 3.0Math.sqrt (- 25); / /-5.0

10. Cbrt (x) returns the cube root of x.

Math.cbrt (27.0) / / 3Math.cbrt (- 125.0); / /-5

11. Log (x) returns the logarithm with the base e.

Math.log (e); / / 1

12. Log10 (x) returns the logarithm with a base of 10.

Math.log10; / / 10

13. Log1p (x)

Math.log1p (x); / / ln (Xero1)

14. Max (xQuery y) returns a larger value.

Math.max (3,10); / / 10Math.max (- 3,-10); / /-3

15. Min (xQuery y) returns a smaller value.

Math.min (3,10); / / 3Math.max (- 3,-10); / /-10

16. Rint (x) is rounded to return the double value. If it is centered at 0.5, an even number is taken.

Math.rint (11.3) / / 11Math.rint (- 11.3); / /-11Math.rint (23.9); / / 23Math.rint (- 23.9); / /-23Math.rint (32.5); / / 32Math.rint (33.5); / / 34

17. Round (x) is the same as rint, and the return value of float is int,double. The return value is long.

Thank you for your reading, the above is the content of "how to use Java mathematical function Math class". After the study of this article, I believe you have a deeper understanding of how to use Java mathematical function Math class, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Functions mathematics learning content parameters logarithms integers same larger rounded even that is ideas situations articles more knowledge knowledge points cube roots symbols Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Microsoft Huawei Shulou Tech Info Xiaomi