Try using java.lang.Math methods


In this article, as part of my output practice, I will note the method of java.lang.Math, which is an API used in mathematical calculations. If there is something wrong with the explanation, it would be helpful if you could point it out. Reference: Official java.lang.Math

abs Find the absolute value of the integer taken as an argument.

  int num1 = Math.abs(-1); //num1 = 1

max, min Returns the larger (smaller) of the two arguments.

  int num2 = Math.max(1,2); //num2 = 2
  int num3 = Math.min(1,2); //num3 = 1

random Returns a positively signed double value greater than or equal to 0.0 and less than 1.0. If you want to make it an integer value, multiply it by an arbitrary multiple before casting.

  //0~Take a random value in the range of 1000
  int num4 = (int)(Math.random()*1000); 

log, log10 log returns the natural logarithm value and log10 returns the common logarithm value.

  double num5 = Math.log(Math.E); //num5 = 1.0
  double num6 = Math.log10(100);  //num6 = 2.0

sin, cos, tan Trigonometric method. Enter radians as arguments. ~~ If you want to input the argument of the radian method, you can convert it by multiplying by $ \ frac {π} {180} $. ~~

  double num7 = Math.sin(Math.PI/4); //1/Approximate value of √2
  double num8 = Math.cos(Math.PI/4); //1/Approximate value of √2
  double num9 = Math.tan(Math.toRadians(45));//1(0.9999999999999999)

pow Returns a double value that is the power of the first argument to the second argument. Cast if treated as an integer value.

  double num10 = Math.pow(10, 4); //num10 = 10000.0

exp, expm1 The former returns the power value of the base $ e $ of the natural logarithm, and the latter returns the number obtained by subtracting 1 from the former. Let's use it in physics and statistics ...?

  double num11 = Math.exp(2);  // e^2
  double num12 = Math.expm1(2);// e^2 -1

sqrt, cbrt Returns the square root and cube root.

  double num13 = Math.sqrt(9);  //num13 = 3.0
  double num14 = Math.cbrt(64); //num14 = 4.0


... I will update it when I find something that I think I will use again.

Recommended Posts

Try using java.lang.Math methods
Try using libGDX
Try using Maven
Try using powermock-mockito2-2.0.2
Try using GraalVM
Try using jmockit 1.48
Try using sql-migrate
Try using SwiftLint
Try using Log4j 2.0
Try using Axon Framework
Try using JobScheduler's REST-API
Try using PowerMock's WhiteBox
Try using Talend Part 2
Try using Talend Part 1
Try using F # list
Try using each_with_index method
Try using Spring JDBC
Try using RocksDB in Java
Try scraping using java [Notes]
Try using Cocoa from Ruby
Try using letter_opener_web for inquiries
[Swift] Try using Collection View
Try using IntelliJ IDEA once
Try using Spring Boot Security
Try using gRPC in Ruby
[Rails] Try using Faraday middleware
[Processing] Try using GT Force.
[Programming Encyclopedia] §2 Try using Ruby
People using docker Try using docker-compose
Write Ruby methods using C (Part 1)
Try using Redmine on Mac docker
Try using Redis with Java (jar)
[Java] Try to implement using generics
Try using the messaging system Pulsar
Try using IBM Java method tracing
Try using Hyperledger Iroha's Java SDK
[Java] Where did you try using java?
Try using Java framework Nablarch [Web application]
Try using || instead of the ternary operator
Try using the service on Android Oreo
Try using the Stream API in Java
Try using the Rails API (zip code)
Study Java Try using Scanner or Map
Try using JSON format API in Java
Try using Spring Boot with VS Code
Try various Java Stream API methods (now)
Write Ruby methods using C (Numo :: NArray)
Call Java methods from Nim using jnim
Try using Reladomo's MT Loader (Multi-Threaded Matcher Loader)
Try using JobScheduler's REST-API --Java RestClient implementation--
Output using methods and constants Learning memo
Try using Kong + Konga with Docker Compose.
Write Ruby methods using C ++ (Part 2) Benchmark
Try using the Emotion API from Android
Try using the Wii remote with Java
Try using simple_form / edit even child models
Try implementing GraphQL server using grahpql-java-tools (+ kotlin)