java.math.*;(一)
package com.test;
/*
Math类:
java.lang.Math类中包含基本的数字操作,如指数、对数、平方根和三角函数。
java.math是一个包,提供用于执行任意精度整数(BigInteger)算法和任意精度小数(BigDecimal)算法的类。
java.lang.Math类中包含E和PI两个静态常量,以及进行科学计算的类(static)方法,可以直接通过类名调用。
public static final Double E = 2.7182818284590452354
public static final Double PI = 3.14159265358979323846
public static long abs(double x):传回 x 的绝对值。X也可int long float
public static long sin(double x): 传回x径度的正弦函数值
public static long cos(double x):传回x径度的余弦函数值
public static long tan(double x): 传回x径度的正切函数值
public static long asin(double x):传回x值的反正弦函数值。
public static long acos(double x):传回x值的反余弦函数值。
public static long atan(double x):传回x值的反正切函数值。
public static long atan2(double x, double y):传回极坐标(polar)的θ值
public static long floor(double x):传回不大于x的最大整数值
public static long ceil(double x):传回不小于x的最小整数值。
public static long exp(double x):传回相当于ex值
public static long log(double x):传回x的自然对数函数值
public static long max(double x,double y):传回x、y较大数
public static long min(double x,double y):传回x、y较小数
public static long pow(double x,double y):传回x的y次幂值
public static long sqrt(double x): 传回x开平方值
public static long rint(double x):传回最接近x的整数值
public static long round(double x):传回x的四舍五入值
public static long toDegrees(double angrad):传回将angrad径度转换成角度
public static long toRadians(double angdeg): 传回将angdeg角度转换成径度
public static long random():传回随机数值,产生一个0-1之间的随机数(不包括0和1)
Math.log(100)/Math.log(10);
表示的是100的以10为底的对数函数的值,是2 向上取整用Math.ceil(double a) 向下取整用Math.floor(double a)。*/public class Mathtest
{
public static void main(String[] args)
{
/*---------下面是三角运算---------*/
//将弧度转换角度
System.out.println("Math.toDegrees(1.57):"
+ Math.toDegrees(1.57));
//将角度转换为弧度
System.out.println("Math.toRadians(90):"
+ Math.toRadians(90));
//计算反余弦,返回的角度范围在 0.0 到 pi 之间。
System.out.println("Math.acos(1.2):" + Math.acos(1.2));
//计算反正弦;返回的角度范围在 -pi/2 到 pi/2 之间。
System.out.println("Math.asin(0.8):" + Math.asin(0.8));
//计算反正切;返回的角度范围在 -pi/2 到 pi/2 之间。
System.out.println("Math.atan(2.3):" + Math.atan(2.3));
//计算三角余弦。
System.out.println("Math.cos(1.57):" + Math.cos(1.57));
//计算值的双曲余弦。
System.out.println("Math.cosh(1.2 ):" + Math.cosh(1.2 ));
//计算正弦
System.out.println("Math.sin(1.57 ):" + Math.sin(1.57 ));
//计算双曲正弦
System.out.println("Math.sinh(1.2 ):" + Math.sinh(1.2 ));
//计算三角正切
System.out.println("Math.tan(0.8 ):" + Math.tan(0.8 ));
//计算双曲正切
System.out.println("Math.tanh(2.1 ):" + Math.tanh(2.1 ));
//将矩形坐标 (x, y) 转换成极坐标 (r, thet));
System.out.println("Math.atan2(0.1, 0.2):" + Math.atan2(0.1, 0.2));
/*---------下面是取整运算---------*/
//取整,返回小于目标数的最大整数。
System.out.println("Math.floor(-1.2 ):" + Math.floor(-1.2 ));
//取整,返回大于目标数的最小整数。
System.out.println("Math.ceil(1.2):" + Math.ceil(1.2));
//四舍五入取整
System.out.println("Math.round(2.3 ):" + Math.round(2.3 ));
/*---------下面是乘方、开方、指数运算---------*/
//计算平方根。
System.out.println("Math.sqrt(2.3 ):" + Math.sqrt(2.3 ));
//计算立方根。
System.out.println("Math.cbrt(9):" + Math.cbrt(9));
//返回欧拉数 e 的n次幂。
System.out.println("Math.exp(2):" + Math.exp(2));
//返回 sqrt(x2 +y2),没有中间溢出或下溢。
System.out.println("Math.hypot(4 , 4):" + Math.hypot(4 , 4));
// 按照 IEEE 754 标准的规定,对两个参数进行余数运算。
System.out.println("Math.IEEEremainder(5 , 2):"
+ Math.IEEEremainder(5 , 2));
//计算乘方
System.out.println("Math.pow(3, 2):" + Math.pow(3, 2));
//计算自然对数
System.out.println("Math.log(12):" + Math.log(12));
//计算底数为 10 的对数。
System.out.println("Math.log10(9):" + Math.log10(9));
//返回参数与 1 之和的自然对数。
System.out.println("Math.log1p(9):" + Math.log1p(9));
/*---------下面是符号相关的运算---------*/
//计算绝对值。
System.out.println("Math.abs(-4.5):" + Math.abs(-4.5));
//符号赋值,返回带有第二个浮点数符号的第一个浮点参数。
// System.out.println("Math.copySign(1.2, -1.0):"
// + Math.copySign(1.2, -1.0));
//符号函数;如果参数为 0,则返回 0;如果参数大于 0,
// 则返回 1.0;如果参数小于 0,则返回 -1.0。
System.out.println("Math.signum(2.3):" + Math.signum(2.3));
/*---------下面是大小相关的运算---------*/
//找出最大值
System.out.println("Math.max(2.3 , 4.5):" + Math.max(2.3 , 4.5));
//计算最小值
System.out.println("Math.min(1.2 , 3.4):" + Math.min(1.2 , 3.4));
//返回第一个参数和第二个参数之间与第一个参数相邻的浮点数。
// System.out.println("Math.nextAfter(1.2, 1.0):"
// + Math.nextAfter(1.2, 1.0));
//返回比目标数略大的浮点数
// System.out.println("Math.nextUp(1.2 ):" + Math.nextUp(1.2 ));
//返回一个伪随机数,该值大于等于 0.0 且小于 1.0。
System.out.println("Math.random():" + Math.random());
}
}
java.math.*;(一)的更多相关文章
- java.math.RoundingMode 几个参数详解
java.math.RoundingMode里面有几个参数搞得我有点晕,现以个人理解对其一一进行总结: 为了能更好理解,我们可以画一个XY轴 RoundingMode.CEILING:取右边最近的整数 ...
- 【java.math.BigInteger】常用函数
1. /* 返回此BigInteger的函数正负号. 此方法返回-1,0或1作为此BigInteger的值对应是负,零或正数. */ java.math.BigInteger.signum(BigIn ...
- 【java.math.BigInteger】【转】常见问题
好大的链接给原作 Q: 在java怎样将BigInteger类型的数据转成int类型的? A:BigInteger的intValue()可以获得int类型数值. Q: java.math.BigInt ...
- [记录]java.math.biginteger cannot be cast to java.lang.long
可以直接使用BigInteger类型进行接收, BigInteger id = (BigInteger)QueryRunner(conn,"SELECT LAST_INSERT_ID&quo ...
- java.math.BigInteger使用心得总结(转)
今天参考课本写了一个关于二进制与十进制转换的程序,程序算法不难,但写完后测试发现不论是二转十还是十转二,对于大于21亿即超过整数范围的数不能很好的转换.都会变成0.参考书籍发现使用使用BigInteg ...
- java.math.BigDecimal类
BigDecimal类用于高精度计算.一般的float型和Double型数据只可以用来做科学计算或者是工程计算,由于在商业计算中,要求的数字精度比较高,所以要用到java.math.BigDecima ...
- java.math.BigDecimal()的用法
Java中简单的浮点数类型float和double是不能进行运算的,不光Java,很多语言都是这样. 我们运行下面程序你将会看到 public class TestMathDecimal { publ ...
- Java中的java.math.BigInteger
Java中的java.math.BigInteger /** * */ package com.you.model; /** * @author YouHaidong * */ public clas ...
- 数据转换失败 java.math.BigDecimal cannot be cast to java.lang.String
从接口获取到数据,在转换的时候出现错误:java.math.BigDecimal cannot be cast to java.lang.String 因为一开始用的是使用关键字进行强制转换,后来发现 ...
- [十五]java.math包简介,RoundingMode与MathContext
java.math包提供了java中的数学类 包括基本的浮点库.复杂运算以及任意精度的数据运算 '可以看得到,主要包括三个类一个枚举 BigDecimal和BigInteger接下来会详细介绍 先 ...
随机推荐
- A Summary of Multi-task Learning
A Summary of Multi-task Learning author by Yubo Feng. Intro In this paper[0], the introduction of mu ...
- 了解C语言
初学时的程序都需要打#include<stdio.h>及int main() //int main中int 声明函数类型为整形,main为主函数:‘//’为注释的意思,后面的内容不会运行 ...
- #map+LCA# Codeforces Round #362 (Div. 2)-C. Lorenzo Von Matterhorn
2018-03-16 http://codeforces.com/problemset/problem/697/C C. Lorenzo Von Matterhorn time limit per t ...
- Bootstrap3基础 text-right/left/center 设置标题右对齐、左对齐、居中
内容 参数 OS Windows 10 x64 browser Firefox 65.0.2 framework Bootstrap 3.3.7 editor ...
- python学习----IO模型
一.IO模型介绍 本文讨论的背景是Linux环境下的network IO. 本文最重要的参考文献是Richard Stevens的"UNIX® Network Programming Vol ...
- 常见的Git命令
最近想着需要把工作中做一个备份,除了本地保存之外,上传到码云是个不错的选择,除了Git的一些特点外,也可以让别人看到你的代码,共同修改之类的 首先在上传到码云之前,需要学习Git的一些基础教程,包括国 ...
- ehcache 简介和基本api使用
文章转载自: https://blog.csdn.net/zhouzhiwengang/article/details/59838105 1.ehcahce简介 在开发高并发量,高性能的网站应用系统时 ...
- 英语发音规则---E字母常见的发音组合有哪些
英语发音规则---E字母常见的发音组合有哪些 一.总结 一句话总结:很好记的e和5个元音字母的组合,加一个非e开头的ie e:开音节 /i:/ eve /i:v/ n. 夏娃----闭音节 /e/ ...
- SQL SERVER 事务的使用(tran)
sql server事务的使用是为了确保数据的一致性. 通常写法 begin tran --sql 语句1 --sql 语句2 --sql 语句3 commit tran 上面写法存在隐患,当操作(增 ...
- java常见3种文件上传速度对比和文件上传方法详细代码
在java里面文件上传的方式很多,最简单的依然是FileInputStream.FileOutputStream了,在这里我列举3种常见的文件上传方法代码,并比较他们的上传速度(由于代码是在本地测试, ...