Skip to content

Commit

Permalink
Reserve more space for decimal points
Browse files Browse the repository at this point in the history
  • Loading branch information
dmgaldi committed Apr 26, 2023
1 parent 1a7007e commit f4b9bbf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// Project settings
group = "org.veupathdb.eda"
version = "4.0.1"
version = "4.0.2"

plugins {
`java-library`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import java.util.Optional;

public class FloatingPointVariable extends NumberVariable<Double> {
private static final int BYTE_COUNT_FOR_INTEGER_DECIMAL_AND_EXP_CHAR = 3;
private static final int BYTE_COUNT_FOR_INTEGER_DECIMAL_AND_EXP_CHAR = 2;
private static final int MAX_DIGITS_BEFORE_SCIENTIFIC_NOTATION = 7;

public static class Properties {
Expand Down Expand Up @@ -66,11 +66,12 @@ public BinaryConverter<String> getStringConverter() {
// size of our string is our precision + 3 bytes for the integer part of the decimal, the "e" in scientific notation
// and the integer part of our value. We also reserve 4 bytes for the size of the padded string.
int integerPartBytes = Integer.toString(_distributionConfig.getRangeMax().intValue()).getBytes(StandardCharsets.UTF_8).length;
int numBytesReservedForIntPart = Math.min(integerPartBytes, 7); // After 7 digits, we start using scientific notation
int numBytesReservedForIntPart = Math.min(integerPartBytes, MAX_DIGITS_BEFORE_SCIENTIFIC_NOTATION); // After 7 digits, we start using scientific notation
int bytesReservedForIntegerPartOrScienitificNotation = Math.max(numBytesReservedForIntPart, BYTE_COUNT_FOR_INTEGER_DECIMAL_AND_EXP_CHAR);
return new StringValueConverter(Integer.BYTES // Reserved for all padded strings
+ bytesReservedForIntegerPartOrScienitificNotation // Reserved for integer part o
+ getPrecision().intValue());
+ bytesReservedForIntegerPartOrScienitificNotation // Reserved for integer part and/or left part of scientific notation.
+ getPrecision().intValue() // Plus space for decimal part.
+ 1); // Plus one for decimal point.
}

@Override
Expand Down

0 comments on commit f4b9bbf

Please sign in to comment.