java超級計算器,jdk自帶類

package lcr;

import java.math.BigInteger;

/**
 * 超級計算器
 * 
 * @author Lee Chuanrong
 *
 */
public class SuperCalculator {

	/*
	 * Add
	 */
	public static BigInteger add(BigInteger a, BigInteger b) {
		return a.add(b);
	}

	/*
	 * Subtract
	 */
	public static BigInteger subtract(BigInteger a, BigInteger b) {
		return a.subtract(b);
	}

	/*
	 * Multiply
	 */
	public static BigInteger multiply(BigInteger a, BigInteger b) {
		return a.multiply(b);
	}

	/*
	 * Divide
	 */
	public static BigInteger divide(BigInteger a, BigInteger b) {
		return a.divide(b);
	}

	public static void main(String[] args) {
		double a = Math.pow(2, 36);
		double b = Math.pow(2, 48);
		BigInteger abi = BigInteger.valueOf((long) a);
		BigInteger bbi = BigInteger.valueOf((long) b);
		System.out.println("a="+a+"\tb="+b);
		System.out.println("Add:\t"+add(abi, bbi));
		System.out.println("Subtract:\t"+subtract(abi, bbi));
		System.out.println("Multiply:\t"+multiply(abi, bbi));
		System.out.println("Divide:\t"+divide(abi, bbi));
	}

}
相關文章
相關標籤/搜索