Ostermillerutil Java Utilities Significant Figures - com.Ostermiller.util Java Utilities

A Java number class for figuring out how many significant figures each of the numbers in a calculation has and displaying the result appropriately.



Example

// Numbers to multiply
String[] args = {"1.0", "2.0"}; 
SignificantFigures number;
int sigs = Integer.MAX_VALUE;
double result = 1D;
for (int i=0; i<args.length; i++){
    // For each number, figure out significant figures
    // and multiply the numbers
    number = new SignificantFigures(args[i]);
    sigs = Math.min(sigs, number.getNumberSignificantFigures());
    result *= number.doubleValue();
}
// format and display the result
number = new SignificantFigures(result);
number.setNumberSignificantFigures(sigs);
System.out.println(number);
Figure significant figures for multiplication of numbers.

Example

// Numbers to add
String[] args = {"1.0", "2.0"}; 
SignificantFigures number;
int lsd = Integer.MIN_VALUE;
int msd = Integer.MIN_VALUE;
double result = 0D;
for (int i=0; i<args.length; i++){
    // for each number figure most and least
    // significant digit then add the number.
    number = new SignificantFigures(args[i]);
    lsd = Math.max(lsd, number.getLSD());
    msd = Math.max(msd, number.getMSD());
    result += number.doubleValue();
}
// format and display the result
number = new SignificantFigures(result);
number.setLMSD(lsd, msd);
System.out.println(number);
Figure significant figures for addition of numbers.

See also: JavaScript routines and an HTML interface for significant figures calculations.



License

OstermillerUtil Java Utilities Copyright (c) 2001-2020 by Stephen Ostermiller and other contributors

The OstermillerUtils library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

License FAQs - Why GPL? How about the LGPL or something else?