Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;

import static java.lang.Math.ceil;
import static java.lang.Math.log;

/**
* Descriptor for {@link Double} handling.
*
Expand All @@ -26,8 +23,6 @@
public class DoubleJavaType extends AbstractClassJavaType<Double> implements
PrimitiveJavaType<Double> {
public static final DoubleJavaType INSTANCE = new DoubleJavaType();
//needed for converting precision from binary to decimal digits
private static final double LOG_BASE10OF2 = log(2)/log(10);

public DoubleJavaType() {
super( Double.class );
Expand Down Expand Up @@ -156,17 +151,14 @@ public long getDefaultSqlLength(Dialect dialect, JdbcType jdbcType) {

@Override
public int getDefaultSqlPrecision(Dialect dialect, JdbcType jdbcType) {
if ( jdbcType.isFloat() ) {
//this is the number of *binary* digits
//in a double-precision FP number
return dialect.getDoublePrecision();
}
else {
return Math.min( dialect.getDefaultDecimalPrecision(), (int) ceil( dialect.getDoublePrecision() * LOG_BASE10OF2 ) );
}
return jdbcType.isFloat()
// this is usually the number of *binary* digits
// in a double-precision FP number
? dialect.getDoublePrecision()
// this is the number of decimal digits in a Java double
: 17;
}


@Override
public <X> Double coerce(X value, CoercionContext coercionContext) {
if ( value == null ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@
import org.hibernate.type.descriptor.jdbc.JdbcType;
import org.hibernate.type.descriptor.jdbc.JdbcTypeIndicators;

import static java.lang.Math.ceil;
import static java.lang.Math.log;

/**
* Descriptor for {@link Float} handling.
*
* @author Steve Ebersole
*/
public class FloatJavaType extends AbstractClassJavaType<Float> implements PrimitiveJavaType<Float> {
public static final FloatJavaType INSTANCE = new FloatJavaType();
//needed for converting precision from binary to decimal digits
private static final double LOG_BASE10OF2 = log(2)/log(10);

public FloatJavaType() {
super( Float.class );
Expand Down Expand Up @@ -154,14 +149,12 @@ public long getDefaultSqlLength(Dialect dialect, JdbcType jdbcType) {

@Override
public int getDefaultSqlPrecision(Dialect dialect, JdbcType jdbcType) {
if ( jdbcType.isFloat() ) {
//this is the number of *binary* digits
//in a single-precision FP number
return dialect.getFloatPrecision();
}
else {
return Math.min( dialect.getDefaultDecimalPrecision(), (int) ceil( dialect.getFloatPrecision() * LOG_BASE10OF2 ) );
}
return jdbcType.isFloat()
// this is usually the number of *binary* digits
// in a single-precision FP number
? dialect.getFloatPrecision()
// this is the number of decimal digits in a Java float
: 8;
}

@Override
Expand Down
Loading