Java math 函数

JavaMath类提供了几种用于数学计算的方法,例如min(),max(),avg(),sin(),cos(),tan(),round(),ceil(),floor(),abs()等

与某些StrictMath类数字方法不同,Math类的等效函数的所有实现都不能定义为返回逐位相同的结果。在不需要严格的可重复性的情况下,这种放宽允许以更好的性能实现。

如果大小为int或long,并且结果超出值的范围,则方法addExact(),subtractExact(),multipleExact()和toIntExact()会引发ArithmeticException。

对于其他算术运算,例如递增,递减,除法,绝对值和取反溢出仅在具有特定的最小值或最大值的情况下发生。应根据最大值和最小值进行检查。

例子1

输出:

Maximum number of x and y is: 28.0

Square root of y is: 2.0

Power of x and y is: 614656.0

Logarithm of x is: 3.332204510175204

Logarithm of y is: 1.3862943611198906

log10 of x is: 1.4471580313422192

log10 of y is: 0.6020599913279624

log1p of x is: 3.367295829986474

exp of a is: 1.446257064291475E12

expm1 of a is: 1.446257064290475E12

例子2

输出:

Sine value of a is: -0.9880316240928618

Cosine value of a is: 0.15425144988758405

Tangent value of a is: -6.405331196646276

Sine value of a is: NaN

Cosine value of a is: NaN

Tangent value of a is: 1.5374753309166493

Sine value of a is: 5.343237290762231E12

Cosine value of a is: 5.343237290762231E12

Tangent value of a is: 1.0

Java数学方法

java.lang.Math类包含各种用于执行基本数字运算的方法,例如对数,立方根和三角函数等。各种Java数学方法如下:

基本数学方法

Method

Description

Math.abs()

It will return the Absolute value of the given value.

Math.max()

It returns the Largest of two values.

Math.min()

It is used to return the Smallest of two values.

Math.round()

It is used to round of the decimal numbers to the nearest value.

Math.sqrt()

It is used to return the square root of a number.

Math.cbrt()

It is used to return the cube root of a number.

Math.pow()

It returns the value of first argument raised to the power to second argument.

Math.signum()

It is used to find the sign of a given value.

Math.ceil()

It is used to find the smallest integer value that is greater than or equal to the argument or mathematical integer.

Math.copySign()

It is used to find the Absolute value of first argument along with sign specified in second argument.

Math.nextAfter()

It is used to return the floating-point number adjacent to the first argument in the direction of the second argument.

Math.nextUp()

It returns the floating-point value adjacent to d in the direction of positive infinity.

Math.nextDown()

It returns the floating-point value adjacent to d in the direction of negative infinity.

Math.floor()

It is used to find the largest integer value which is less than or equal to the argument and is equal to the mathematical integer of a double value.

Math.floorDiv()

It is used to find the largest integer value that is less than or equal to the algebraic quotient.

Math.random()

It returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.

Math.rint()

It returns the double value that is closest to the given argument and equal to mathematical integer.

Math.hypot()

It returns sqrt(x2 +y2) without intermediate overflow or underflow.

Math.ulp()

It returns the size of an ulp of the argument.

Math.getExponent()

It is used to return the unbiased exponent used in the representation of a value.

Math.IEEEremainder()

It is used to calculate the remainder operation on two arguments as prescribed by the IEEE 754 standard and returns value.

Math.addExact()

It is used to return the sum of its arguments, throwing an exception if the result overflows an int or long.

Math.subtractExact()

It returns the difference of the arguments, throwing an exception if the result overflows an int.

Math.multiplyExact()

It is used to return the product of the arguments, throwing an exception if the result overflows an int or long.

Math.incrementExact()

It returns the argument incremented by one, throwing an exception if the result overflows an int.

Math.decrementExact()

It is used to return the argument decremented by one, throwing an exception if the result overflows an int or long.

Math.negateExact()

It is used to return the negation of the argument, throwing an exception if the result overflows an int or long.

Math.toIntExact()

It returns the value of the long argument, throwing an exception if the value overflows an int.

对数数学方法

Method

Description

Math.log()

It returns the natural logarithm of a double value.

Math.log10()

It is used to return the base 10 logarithm of a double value.

Math.log1p()

It returns the natural logarithm of the sum of the argument and 1.

Math.exp()

It returns E raised to the power of a double value, where E is Euler’s number and it is approximately equal to 2.71828.

Math.expm1()

It is used to calculate the power of E and subtract one from it.

三角数学方法

Method

Description

Math.sin()

It is used to return the trigonometric Sine value of a Given double value.

Math.cos()

It is used to return the trigonometric Cosine value of a Given double value.

Math.tan()

It is used to return the trigonometric Tangent value of a Given double value.

Math.asin()

It is used to return the trigonometric Arc Sine value of a Given double value

Math.acos()

It is used to return the trigonometric Arc Cosine value of a Given double value.

Math.atan()

It is used to return the trigonometric Arc Tangent value of a Given double value.

双曲数学方法

Method

Description

Math.sinh()

It is used to return the trigonometric Hyperbolic Cosine value of a Given double value.

Math.cosh()

It is used to return the trigonometric Hyperbolic Sine value of a Given double value.

Math.tanh()

It is used to return the trigonometric Hyperbolic Tangent value of a Given double value.

角数学方法

Method

Description

Math.toDegrees

It is used to convert the specified Radians angle to equivalent angle measured in Degrees.

Math.toRadians

It is used to convert the specified Degrees angle to equivalent angle measured in Radians.

0

相关文章:Java中的StringBuffer appendCodePoint()方法以及示例 java.lang.StringBuffer.appendCodePoint(int cp)是将codePoi […]...

Java中的访问修饰符 顾名思义,Java中的访问修饰符有助于限制类,构造函数,变量,方法或数据成员的范围。Java中有四种可用的访问 […]...

父类和子类在Java中具有相同的数据成员 父类的引用变量能保存其对象引用及其子对象引用。 在Java中,方法是默认虚拟。 非方法成员呢?例如,预测以下J […]...

Java中的字符串到整数– parseInt() 在对字符串进行操作时,有时需要将以字符串表示的数字转换为整数类型。在Java中通常用于将String转换为In […]...

Java中的Super关键字 Java中的super关键字是一个引用变量,用于引用父类对象。关键字“ super”以继承的概念出 […]...

Java 8中的默认方法 在Java 8之前,接口只能具有抽象方法。这些方法的实现必须在单独的类中提供。因此,如果要在接口中添加新方法, […]...

Java中的嵌套接口 我们可以将接口声明为类或其他接口的成员。这样的接口称为成员接口或嵌套接口。 在类接口的任何其他类。在类中声明的 […]...

Java中的对象和类 Java中的对象和类 在此页面中,我们将学习Java对象和类。在面向对象的编程技术中,我们使用对象和类设计程序 […]...

math.hypot java_Java math相关推荐

  1. math.hypot java_Java Math.hypot() 方法

    Java Math.hypot() 方法 java.lang.Math.hypot() 用于返回的指定的参数的平方和的平方根,没有中间溢出或下溢. 1 语法 public static double ...

  2. math.hypot java_Java Math hypot()用法及代码示例

    java.lang.Math.hypot()函数是Java中的内置数学函数,可返回欧几里得范数, .函数返回sqrt(x2+ y2),而不会出现中间上溢或下溢. 如果任何一个参数都是无限大,则结果为正 ...

  3. math.hypot java_Java之Math类

    Java之Math类# Java的Math类封装了很多与数学有关的属性和方法,后续遇到常用也会直接在这篇博客更新...### public static void t2() { System.out. ...

  4. math.hypot java_java.lang.Math.hypot(double x, double y)方法实例

    全屏 java.lang.Math.hypot(double x, double y) 返回 sqrt(x2 +y2) 没有中间溢或下溢.特殊情况:如果任一参数为无穷大,那么结果为正无穷大. 如果任一 ...

  5. math.floor java_Java Math.floor() 方法

    Java Math.floor() 方法 java.lang.Math.floor() 返回最大的(最接近正无穷大)double值,该值小于或等于参数,并等于某个整数. 1 语法 public sta ...

  6. js math.hypot_带有Python示例的math.hypot()方法

    js math.hypot Python math.hypot()方法 (Python math.hypot() method) math.hypot() method is a library me ...

  7. boost::math::hypot用法的测试程序

    boost::math::hypot用法的测试程序 实现功能 C++实现代码 实现功能 boost::math::hypot用法的测试程序 C++实现代码 #include <pch_light ...

  8. python中import math用法_Python math.hypot() 方法

    Python math.hypot() 方法 例如: 找到已知垂直和底角的直角三角形的斜边:#Import math Library import math #垂线与底面 parendicular = ...

  9. python3 math module_Python math hypot()用法及代码示例

    hypot()函数是Python中的内置数学函数,可返回欧几里得范数, . 用法: hypot(x, y) 参数: x and y are numerical values 返回值: Returns ...

最新文章

  1. mysql 一键安装 linux_linux下mysql8 shell脚本一键安装
  2. 薪资不逊NLP算法岗,边缘AI火了!
  3. 野生前端的数据结构练习(10)希尔排序,归并排序,快速排序
  4. java线程同步例子_JAVA线程同步实例教程
  5. mysql 5.5 外键_MySQL 5.5添加外键失败,错误[HY000] [150]和[HY000] [1005]
  6. java批量导入和批量删除_MyBatis 实现批量插入和删除中双层循环的写法案例
  7. FRR BGP 协议分析 5 -- 路由更新(2)
  8. LNMP一键安装的卸载
  9. ass字幕导入Premiere的另一种思路 用ffmpeg把ass转换成颜色通道和透明度通道两个视频
  10. 斐讯K2一键刷华硕固件支持最新固件22.5.10.176
  11. Java千百问_05面向对象(003)_java中抽象概念如何体现的
  12. 正大国际:期货日内波段交易
  13. UE4学习之VR(三)
  14. Excel中的美元符号$
  15. 写在Groovy/Grails栏目开通的话
  16. 计算机绘图cad期末考试试题,2017大学cad期末考试练习题「附答案」
  17. DynaBeanHolder动态bean构造器实现
  18. python3入门指南_Python 3.4入门指南
  19. c语言求偶数的积,动物行为学1
  20. 计算机的医学应用,计算机技术在医学中的应用

热门文章

  1. sap系统搭建教程_Nios ii最小系统搭建教程
  2. ios 企业签名需要源文件么_苹果企业签名之iOS证书申请和签名文件生成
  3. vscode从原有分支上新建_GitHub+VSCode 打造稳定、快速、高效、免费图床
  4. YYDS 的 IDEA插件,没装上的安排起来!
  5. Facebook 分享 MySQL 5.6 到 8.0 的迁移经验
  6. 别再搞错!OAuth 2.0只是授权协议,OIDC才是认证授权协议
  7. OpenAPI 规范 3.1.0 发布,赶紧来尝尝鲜!
  8. 微信年末最后一发新功能!对生活很有帮助,必须了解一下!
  9. Dubbo 管理能力弱?Dubbo Admin 发布 v0.1 助力服务管理能力!
  10. linux 公私钥生成,[c++,openssl,RSA] linux下编程实现生成公私钥对_1