A utility class for numerical analysis. This class cannot be subclassed or instantiated because all methods are static. @author Wolfgang Christian @version 1.0
| 21 | * @version 1.0 |
| 22 | */ |
| 23 | public final class Util { |
| 24 | public static final double SQRT2PI = Math.sqrt(2*Math.PI); |
| 25 | public static final double LOG10 = Math.log(10); |
| 26 | |
| 27 | /** The default precision for numerical analysis. */ |
| 28 | public static final double defaultNumericalPrecision = Math.sqrt(Double.MIN_VALUE); |
| 29 | |
| 30 | private static Map<String, DecimalFormat> htFormats = new Hashtable<>(); |
| 31 | |
| 32 | public static DecimalFormat newDecimalFormat(String format) { |
| 33 | DecimalFormat f = htFormats.get(format); |
| 34 | if (f == null) { |
| 35 | f = new DecimalFormat(format); |
| 36 | htFormats.put(format, f); |
| 37 | } |
| 38 | return f; |
| 39 | } |
| 40 | |
| 41 | /** Parser for simple arithmetic expressions. */ |
| 42 | private static SuryonoParser parser = new SuryonoParser(0); // parser without variables |
| 43 | // standard output formats |
| 44 | static DecimalFormat format2 = org.opensourcephysics.numerics.Util.newDecimalFormat("#0.00"); //$NON-NLS-1$ |
| 45 | static DecimalFormat format3 = org.opensourcephysics.numerics.Util.newDecimalFormat("#0.000"); //$NON-NLS-1$ |
| 46 | static DecimalFormat format4 = org.opensourcephysics.numerics.Util.newDecimalFormat("#0.0000"); //$NON-NLS-1$ |
| 47 | static DecimalFormat format_E2 = org.opensourcephysics.numerics.Util.newDecimalFormat("0.00E0"); //$NON-NLS-1$ |
| 48 | static DecimalFormat format_E3 = org.opensourcephysics.numerics.Util.newDecimalFormat("0.000E0"); //$NON-NLS-1$ |
| 49 | static DecimalFormat format_E4 = org.opensourcephysics.numerics.Util.newDecimalFormat("0.0000E0"); //$NON-NLS-1$ |
| 50 | |
| 51 | private Util() {} // prohibit instantiation because all methods are static |
| 52 | |
| 53 | |
| 54 | |
| 55 | /** |
| 56 | * Convert a double to a string, printing two decimal places. |
| 57 | * @param d Input double |
| 58 | */ |
| 59 | static public String f2(double d) { |
| 60 | return format2.format(d); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * Convert a double to a string, printing three decimal places. |
| 65 | * @param d Input double |
| 66 | */ |
| 67 | static public String f3(double d) { |
| 68 | return format3.format(d); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Convert a double to a string, printing four decimal places. |
| 73 | * @param d Input double |
| 74 | */ |
| 75 | static public String f4(double d) { |
| 76 | return format4.format(d); |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Computes the relativePrecision except near zero where the absolute precision is returned. |
nothing calls this directly
no test coverage detected