1 /* 2 * Copyright (c) 2018, Raffaello Giulietti. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * This particular file is subject to the "Classpath" exception as provided 9 * in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 */ 21 22 import java.math.BigDecimal; 23 24 /** 25 * @author Raffaello Giulietti 26 */ 27 class DoubleToStringChecker extends StringChecker { 28 29 private double v; 30 31 DoubleToStringChecker(double v, String s) { 32 super(s); 33 this.v = v; 34 } 35 36 @Override 37 BigDecimal toBigDecimal() { 38 return new BigDecimal(v); 39 } 40 41 @Override 42 boolean recovers(BigDecimal b) { 43 return b.doubleValue() == v; 44 } 45 46 @Override 47 boolean recovers(String s) { 48 return Double.parseDouble(s) == v; 49 } 50 51 @Override 52 int maxExp() { 53 return 309; 54 } 55 56 @Override 57 int minExp() { 58 return -323; 59 } 60 61 @Override 62 int maxLen10() { 63 return 17; 64 } 65 66 @Override 67 boolean isZero() { 68 return v == 0; 69 } 70 71 @Override 72 boolean isInfinity() { 73 return v == Double.POSITIVE_INFINITY; 74 } 75 76 @Override 77 void invert() { 78 v = -v; 79 } 80 81 @Override 82 boolean isNegative() { 83 return Double.doubleToRawLongBits(v) < 0; 84 } 85 86 @Override 87 boolean isNaN() { 88 return v != v; 89 } 90 91 }