zoukankan      html  css  js  c++  java
  • Java_大数值_16.5.12

      如果基本的整数和浮点数精度不能满足要求,那么可以使用java.math包中的BigInteger和BigDecimal这两个类。这两个类可以处理包含任意长度数字序列的数值。BigInteger类实现了任意精度的整数运算,BigDecimal实现了任意精度的浮点数运算。  

      使用静态的valueOf方法可以将普通的数值转换为大数值:BigInteger a=BigInteger.valueOf(100);

      不能使用普通的算数运算符处理大数,而是用类中的add和multiply方法。

        BigInteger c=a.add(b);

        Biginteger d=c.multiply(b.add(BigInteger.valueOf(2)));   // d=c*(b+2)

      求和,差,积,商,余数:

        Biginteger add(BigInteger other)

        BigInteger subtract(BigInteger other)

        BigInteger multiply(BigInteger other)

        BigInteger divide(BigInteger other)

        Biginteger mod(BigInteger other)

      比较大小(相等返回0,这个数大于other返回正数,否则返回负数)

        int compareTo(BigInteger other)

      BigDecimal类中的方法大致一致。

  • 相关阅读:
    LDA模型了解及相关知识
    GAN
    tensorflow学习6
    GAN的文献综述
    python相关工具
    tensorflow学习5----变量管理
    tensorflow学习5----GAN模型初探
    8月14日至8月20日技术积累
    8月7日至8月13日技术积累
    8月1日到8月6日技术要点
  • 原文地址:https://www.cnblogs.com/jasonlixuetao/p/5487490.html
Copyright © 2011-2022 走看看