1 9 package org.jscience.physics.units; 10 11 import javolution.lang.MathLib; 12 13 23 public final class LogConverter extends Converter { 24 25 28 private final double _base; 29 30 33 private final double _logBase; 34 35 38 private final double _invLogBase; 39 40 43 private final Inverse _inverse = new Inverse(); 44 45 51 public LogConverter(double base) { 52 _base = base; 53 _logBase = MathLib.log(base); 54 _invLogBase = 1.0 / _logBase; 55 } 56 57 63 public double getBase() { 64 return _base; 65 } 66 67 public Converter inverse() { 69 return _inverse; 70 } 71 72 public double convert(double x) { 74 return _invLogBase * MathLib.log(x); 75 } 76 77 public double derivative(double x) { 79 return _invLogBase / x; 80 } 81 82 public boolean isLinear() { 84 return false; 85 } 86 87 public boolean equals(Object obj) { 89 return (obj instanceof LogConverter) 91 && (Float.floatToIntBits((float) ((LogConverter) obj)._base) == Float 92 .floatToIntBits((float) _base)); 93 } 94 95 public int hashCode() { 97 return Float.floatToIntBits((float) _base); 98 } 99 100 104 private class Inverse extends Converter { 105 106 public Converter inverse() { 108 return LogConverter.this; 109 } 110 111 public double convert(double x) { 113 return MathLib.exp(_logBase * x); 114 } 115 116 public double derivative(double x) { 118 return _logBase * MathLib.exp(x); 119 } 120 121 public boolean isLinear() { 123 return false; 124 } 125 126 public boolean equals(Object obj) { 128 return (obj instanceof Inverse) 129 && LogConverter.this.equals(((Inverse) obj).inverse()); 130 } 131 132 public int hashCode() { 134 return LogConverter.this.hashCode() * 31; 135 } 136 137 private static final long serialVersionUID = 1L; 138 } 139 140 private static final long serialVersionUID = 1L; 141 } | Popular Tags |