You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@phoenix.apache.org by "Shuxiong Ye (JIRA)" <ji...@apache.org> on 2015/04/08 07:49:12 UTC

[jira] [Created] (PHOENIX-1825) PDecimal fails to store 1E-127

Shuxiong Ye created PHOENIX-1825:
------------------------------------

             Summary: PDecimal fails to store 1E-127
                 Key: PHOENIX-1825
                 URL: https://issues.apache.org/jira/browse/PHOENIX-1825
             Project: Phoenix
          Issue Type: Bug
            Reporter: Shuxiong Ye


{code}
BigDecimal v = BigDecimal.valueOf(1e-127);
LiteralExpression literal;
literal = LiteralExpression.newConstant(v, PDecimal.INSTANCE, SortOrder.ASC);
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
literal.evaluate(null, ptr);
System.out.println(v);                                  // 1.0E-127
System.out.println(PDecimal.INSTANCE.toObject(ptr));    // 1E+129
System.out.println(Double.MIN_VALUE);                   // 4.9E-324
{code}

The code above shows that when we put 1.0E-127 in PDecimal, it turns out to be 1E+129. The reason is, in PDecimal, the length of exponent is 1 byte(see details in PDataType#toBytes and PDataType#toBigDecimal), while in BigDecimal, the scale is a 4-byte int.

As a reference, Double.MIN_VALUE equals 4.9e-324, which is the smallest positive nonzero double value.




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)