Common math Methods in Java

Source: Internet
Author: User
Tags abs float max pow

Java.lang.Math:

 Absolute Value:static int abs (int a)Static long abs (long a)Static float abs (float a)static Double abs (double A) extremum:static int max (int a, int b)Static Long Max (long A, long B)static float Max (float A, float b)static Double Max (double A, double b)static int min (int a, int b)static Long min (long a, long B)static float min (float A, float b)static Double min (double A, double b) triangle:static Double sin (double A)//sine functionstatic Double Sinh (double x)//hyperbolic sine function static double cos (double a)//cosine functionstatic Double cosh (double x)//hyperbolic cosine function static Double tan (double A)//tangent functionstatic Double Tanh (double x)//hyperbolic tangent function static double asin (double A)static Double ACOs (double A)static Double Atan (double A)static Double atan2 (double y, double x) logarithm, exponent:static double log (double a)static Double log10 (double A)static Double log1p (double x)//ln (x+1) static double exp (double A)static Double expm1 (double x)//E^a-1 power, Root:static Double pow (double A, double b)static double sqrt (double A)static Double CBRT (double A)//cube rootstatic Double Hypot (double x, double y)//sqrt ( x2 + y2)static Double Scalb (double D, int scalefactor)// D x2 scaleFactor Static float scalb (float f, int scalefactor)// f x2 scaleFactor  Random:static double random () The nearest integer:Static Long round (double a)Static int round (float a) floating point number:static double Nextafter (double start, double direction)Static float Nextafter (float start, double direction)static Double Nextdown (double D)Static float Nextdown (float f)static Double Nextup (double D)Static float Nextup (float f)static Double Ceil (double A)static double floor (double a)static int Floordiv (int x, int y)Static Long Floordiv (long x, long y)static int Floormod (int x, int y)Static Long Floormod (long x, long y)  No overflow calculation: throws an exception if overflowstatic int tointexact (Long value)static int addexact (int x, int y)Static Long Addexact (long x, long y)static int subtractexact (int x, int y)Static Long Subtractexact (long x, long y)static int multiplyexact (int x, int y)Static Long Multiplyexact (long x, long y)static int negateexact (int a)Static Long Negateexact (long a)static int incrementexact (int a)Static Long Incrementexact (long a)static int decrementexact (int a)Static Long Decrementexact (long a) Symbols:static Double Signum (double D)Static float Signum (float f) Angle Conversion:static Double todegrees (double Angrad)static Double Toradians (double angdeg) Other:static int getexponent (double D)static int getexponent (float f) static double rint (double A)//round int static double copysign (double magnitude, double sign)//Use the magnitude value and symbolStatic float copysign (float magnitude, float sign) static Double IEEERemainder (double F1, double F2)//F1 divided by F2 remainder static Double Ulp (double D)Static float Ulp (float f)
1  Packagecom.hone.test;2 3 /**4 * Methods for testing Java.lang.Math5  * @authorXia6  *7  */8  Public classMaths {9 Ten      Public Static voidMain (string[] args) { One         DoubleD = 123.456; A         DoubleD2 =-123.456; -          -         inti = 123; the         intb = 389; -System.out.printf ("%.2f%n", D2);//Output 2 decimal places by format -System.out.printf ("%.3f%n", Math.Abs (D2));//Math.Abs (D2) Get absolute value -          +         //------------There is no overflow calculation and throws an exception if there is an overflow-------------------- - System.out.println (Math.addexact (i, b)); +System.out.println (Math.incrementexact (i));//if overflow, add 1------124 A          at         //------------extremum-------------------- -System.out.println (Math.max (d, D2));//Select a larger value 123.456 -System.out.println (Math.min (i, b));//Select a smaller value 123 -          -         //------------logarithm, exponent-------------------- -System.out.println (Math.log (d));//outputs the logarithm of the base e inSystem.out.println (MATH.LOG10 (100.0));//output logarithm with base 10 -System.out.println (MATH.LOG10 (100.0));//output logarithm with base 10 to          +System.out.println (Math.exp (1));//output an e-base index -          the         //------------Power, Root:-------------------- *System.out.println (Math.pow (d, D2));//represents D^D2 $System.out.println (Math.sqrt (d));//take the root mean square of DPanax NotoginsengSystem.out.println (MATH.CBRT (1000));//Cubic Root -          the         //------------random number-------------------- +System.out.println (Math.random ());//random number between (0,1) A          the         //------------The nearest integer:-------------------- +System.out.println (Math.Round (d));//Rounding Rounded rounding -          $System.out.println (Math.ceil (d));//Rounding up $System.out.println (Math.floor (d));//Rounding down -     } -}

Common math Methods in Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.