package com.lovecoding.day14.api01;

import org.junit.Test;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
import java.util.Random;

public class TestMath {
    //Random
    @Test
    public void test04(){
        Random random = new Random();

        System.out.println(random.nextInt());
        // 0 - 100 不包含100
        System.out.println(random.nextInt(100));

        double v = random.nextDouble();
        System.out.println(v);
    }
    //BigDecimal
    @Test
    public void test03(){
        BigDecimal b1 = new BigDecimal("1.000000000000000000000000000000000000000001");
        BigDecimal b2 = new BigDecimal("1.000000000000000000000000000000000000000002");

        System.out.println(b1.add(b2));
        System.out.println(b1.subtract(b2));
        System.out.println(b1.multiply(b2));
        System.out.println(b1.remainder(b2));

        //System.out.println(b1.divide(b2));
        System.out.println(b1.divide(b2,2));
        System.out.println(b1.divide(b2, RoundingMode.CEILING));
    }

    //int integer
    @Test
    public void test02(){
        //为什么编译错误？  12345678910 超范围
        int i1 = 1234567891;
        long l1 = 12345678910L; //必须加L: 不加 默认int
        // long l2 = 12345678910123123123123123L; //有long 存不下的值

        //做百万级的计算器 ？ 怎么实现
        BigInteger big1 = new BigInteger("12345678910123123123123123");
        BigInteger big2 = new BigInteger("12345678910000000000000000");
        System.out.println(big1);

        //方法 链式调用
        System.out.println(big1.add(big2));
        System.out.println(big1.subtract(big2));
        System.out.println(big1.multiply(big2));
        System.out.println(big1.divide(big2));
        System.out.println(big1.remainder(big2));

    }

    /*
     * public static double pow(double a,double b)：返回a的b幂次方法
     * public static double sqrt(double a)：返回a的平方根
     * public static double random()：返回[0,1)的随机值
     * static long round(double a) 四舍五入。
     * public static final double PI：返回圆周率
     * public static double max(double x, double y)：返回x,y中的最大值
     * public static double min(double x, double y)：返回x,y中的最小值
     */
    @Test
    public void test01(){
        //返回a的b幂次方法
        System.out.println(Math.pow(2, 2));
        System.out.println(Math.pow(2, 3));

        //返回a的平方根
        System.out.println(Math.sqrt(4));

        //返回[0,1)的随机值
        System.out.println(Math.random());

        //四舍五入
        long round = Math.round(3.56);
        System.out.println(round);

        //返回圆周率
        System.out.println(Math.PI);

        //返回x,y中的最大值
        System.out.println(Math.max(11,22));

        //绝对值
        System.out.println(Math.abs(-10));

        //问？
        System.out.println(Math.round(-3.46));

        //Math.random() 返回  50 100 )之间的随机数？
        int v = (int) (Math.random() * 50) + 50;//0 -0.999999  0 - 49
        System.out.println(v);
    }
}
