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

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

    [ https://issues.apache.org/jira/browse/PHOENIX-1825?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14484927#comment-14484927 ] 

James Taylor commented on PHOENIX-1825:
---------------------------------------

The Phoenix DECIMAL does not store the full range of a BigDecimal as the exponent is limited to 1 byte. I'll morph this JIRA into documenting the range and flagging attempts to store a BigDecimal outside of the allowed range as an error.

> 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)