Skip to content

Commit ee51a1d

Browse files
committed
Fixed bug with values around the minimum subnormal value becoming 0
1 parent 3c97b1d commit ee51a1d

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>at.syntaxerror</groupId>
44
<artifactId>ieee754-java</artifactId>
5-
<version>2.1.0</version>
5+
<version>2.1.1</version>
66
<name>IEEE754-Java</name>
77
<description>A Java 19 library for converting between IEEE 754 binary and decimal and BigDecimal</description>
88
<licenses>
@@ -64,7 +64,7 @@
6464
<path>
6565
<groupId>org.projectlombok</groupId>
6666
<artifactId>lombok</artifactId>
67-
<version>1.18.20</version>
67+
<version>1.18.30</version>
6868
</path>
6969
</annotationProcessorPaths>
7070
</configuration>
@@ -111,15 +111,15 @@
111111
<dependency>
112112
<groupId>org.projectlombok</groupId>
113113
<artifactId>lombok</artifactId>
114-
<version>1.18.24</version>
114+
<version>1.18.30</version>
115115
<scope>provided</scope>
116116
</dependency>
117117

118118
<!-- for BigDecimal logarithm -->
119119
<dependency>
120120
<groupId>ch.obermuhlner</groupId>
121121
<artifactId>big-math</artifactId>
122-
<version>2.3.0</version>
122+
<version>2.3.2</version>
123123
</dependency>
124124

125125
<!-- JUnit 5 -->

src/main/java/at/syntaxerror/ieee754/binary/BinaryCodec.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,14 @@ else if(bitCount == 0)
270270
int bits = significand.bitLength();
271271

272272
significand = significand.add(BigInteger.ONE);
273+
274+
int newBits = significand.bitLength();
273275

274-
if(bits != significand.bitLength()) { // overflow occured, adjust exponent
276+
if(bits < newBits) { // overflow occured, adjust exponent
277+
278+
if(newBits > this.significand + off)
279+
significand = significand.clearBit(newBits - 1); // clear overflown bit
275280

276-
significand = significand.clearBit(bits); // clear overflown bit
277281
++exp;
278282

279283
// if exponent is all 1s now, return Infinity
@@ -298,7 +302,7 @@ else if(bitCount == 0)
298302
.or(significand.shiftLeft(this.significand - eMin + exp - len + 2));
299303

300304
// clear most significant bit if number is implicit
301-
if(implicit)
305+
if(implicit && len > 0)
302306
significand = significand.clearBit(len - 1);
303307

304308
BigInteger result = BigInteger.valueOf(sign)

0 commit comments

Comments
 (0)