< prev index next >
src/java.base/share/classes/jdk/internal/math/FloatingDecimal.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 2375,2386 ****
// else all of string was seen, round and sticky are
// correct as false.
// Float calculations
int floatBits = isNegative ? FloatConsts.SIGN_BIT_MASK : 0;
! if (exponent >= FloatConsts.MIN_EXPONENT) {
! if (exponent > FloatConsts.MAX_EXPONENT) {
// Float.POSITIVE_INFINITY
floatBits |= FloatConsts.EXP_BIT_MASK;
} else {
int threshShift = DoubleConsts.SIGNIFICAND_WIDTH - FloatConsts.SIGNIFICAND_WIDTH - 1;
boolean floatSticky = (significand & ((1L << threshShift) - 1)) != 0 || round || sticky;
--- 2375,2386 ----
// else all of string was seen, round and sticky are
// correct as false.
// Float calculations
int floatBits = isNegative ? FloatConsts.SIGN_BIT_MASK : 0;
! if (exponent >= Float.MIN_EXPONENT) {
! if (exponent > Float.MAX_EXPONENT) {
// Float.POSITIVE_INFINITY
floatBits |= FloatConsts.EXP_BIT_MASK;
} else {
int threshShift = DoubleConsts.SIGNIFICAND_WIDTH - FloatConsts.SIGNIFICAND_WIDTH - 1;
boolean floatSticky = (significand & ((1L << threshShift) - 1)) != 0 || round || sticky;
*** 2407,2422 ****
}
}
float fValue = Float.intBitsToFloat(floatBits);
// Check for overflow and update exponent accordingly.
! if (exponent > DoubleConsts.MAX_EXPONENT) { // Infinite result
// overflow to properly signed infinity
return isNegative ? A2BC_NEGATIVE_INFINITY : A2BC_POSITIVE_INFINITY;
} else { // Finite return value
! if (exponent <= DoubleConsts.MAX_EXPONENT && // (Usually) normal result
! exponent >= DoubleConsts.MIN_EXPONENT) {
// The result returned in this block cannot be a
// zero or subnormal; however after the
// significand is adjusted from rounding, we could
// still overflow in infinity.
--- 2407,2422 ----
}
}
float fValue = Float.intBitsToFloat(floatBits);
// Check for overflow and update exponent accordingly.
! if (exponent > Double.MAX_EXPONENT) { // Infinite result
// overflow to properly signed infinity
return isNegative ? A2BC_NEGATIVE_INFINITY : A2BC_POSITIVE_INFINITY;
} else { // Finite return value
! if (exponent <= Double.MAX_EXPONENT && // (Usually) normal result
! exponent >= Double.MIN_EXPONENT) {
// The result returned in this block cannot be a
// zero or subnormal; however after the
// significand is adjusted from rounding, we could
// still overflow in infinity.
*** 2432,2442 ****
(DoubleConsts.SIGNIFICAND_WIDTH - 1))
& DoubleConsts.EXP_BIT_MASK) |
(DoubleConsts.SIGNIF_BIT_MASK & significand);
} else { // Subnormal or zero
! // (exponent < DoubleConsts.MIN_EXPONENT)
if (exponent < (DoubleConsts.MIN_SUB_EXPONENT - 1)) {
// No way to round back to nonzero value
// regardless of significand if the exponent is
// less than -1075.
--- 2432,2442 ----
(DoubleConsts.SIGNIFICAND_WIDTH - 1))
& DoubleConsts.EXP_BIT_MASK) |
(DoubleConsts.SIGNIF_BIT_MASK & significand);
} else { // Subnormal or zero
! // (exponent < Double.MIN_EXPONENT)
if (exponent < (DoubleConsts.MIN_SUB_EXPONENT - 1)) {
// No way to round back to nonzero value
// regardless of significand if the exponent is
// less than -1075.
*** 2472,2482 ****
}
// Now, discard the bits
significand = significand >> bitsDiscarded;
! significand = ((((long) (DoubleConsts.MIN_EXPONENT - 1) + // subnorm exp.
(long) DoubleConsts.EXP_BIAS) <<
(DoubleConsts.SIGNIFICAND_WIDTH - 1))
& DoubleConsts.EXP_BIT_MASK) |
(DoubleConsts.SIGNIF_BIT_MASK & significand);
}
--- 2472,2482 ----
}
// Now, discard the bits
significand = significand >> bitsDiscarded;
! significand = ((((long) (Double.MIN_EXPONENT - 1) + // subnorm exp.
(long) DoubleConsts.EXP_BIAS) <<
(DoubleConsts.SIGNIFICAND_WIDTH - 1))
& DoubleConsts.EXP_BIT_MASK) |
(DoubleConsts.SIGNIF_BIT_MASK & significand);
}
< prev index next >