[ https://issues.apache.org/jira/browse/VELTOOLS-196?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Christopher Schultz updated VELTOOLS-196: ----------------------------------------- Description: I found this while trying to create random numbers with a huge range. Without thinking too hard about it, I did: $math.random(1,99999999999999999999) That's 20 nines all lined-up, which turns out to be larger than Long.MAX_VALUE. The result is that my random number is _always_ Long.MAX_VALUE. I tracked this down to MathTool.random's use of MathTool.matchType, which returns either an Integer or a Long value, depending upon whether the value-to-match-types is outside the range of [ Integer.MIN_VALUE - Integer.MAX_VALUE ]. Well, there are double values which are higher than Long.MAX_VALUE, too, and those should return a BigInteger value instead of a Long. If I call $math.toNumber(99999999999999999999), I get a BigInteger and so I'd expect that MathTool.random() would be able to return a BigInteger as well. So I think we just need another clause which checks to see if Long isn't big enough, and return a BigInteger instead. (We might want to think about supporting BigDouble, too, but that's outside the scope of this bug report.) was: I found this while trying to create random numbers with a huge range. Without thinking too hard about it, I did: $math.random(1,99999999999999999999) That's 20 nines all lined-up, which turns out to be larger than Long.MAX_VALUE. The result is that my random number is always Long.MAX_DOUBLE. I tracked this down to MathTool.random's use of MathTool.matchTypes, which returns either an Integer or a Long value, depending upon whether the value-to-match-types is outside the range of [ Integer.MIN_VALUE - Integer.MAX_VALUE ]. Well, there are double values which are higher than Long.MAX_VALUE, too, and those should return a BigInteger value instead of a Long. If I call $math.toNumber(99999999999999999999), I get a BigInteger and so I'd expect that MathTool.random() would be able to return a BigInteger as well. So I think we just need another clause which checks to see if Long isn't big enough, and return a BigInteger instead. (We might want to think about supporting BigDouble, too, but that's outside the scope of this bug report.) > MathTool.matchType can truncate integral values > ----------------------------------------------- > > Key: VELTOOLS-196 > URL: https://issues.apache.org/jira/browse/VELTOOLS-196 > Project: Velocity Tools > Issue Type: Bug > Affects Versions: 3.1 > Reporter: Christopher Schultz > Priority: Minor > > I found this while trying to create random numbers with a huge range. Without > thinking too hard about it, I did: > $math.random(1,99999999999999999999) > That's 20 nines all lined-up, which turns out to be larger than > Long.MAX_VALUE. The result is that my random number is _always_ > Long.MAX_VALUE. > I tracked this down to MathTool.random's use of MathTool.matchType, which > returns either an Integer or a Long value, depending upon whether the > value-to-match-types is outside the range of [ Integer.MIN_VALUE - > Integer.MAX_VALUE ]. > Well, there are double values which are higher than Long.MAX_VALUE, too, and > those should return a BigInteger value instead of a Long. > If I call $math.toNumber(99999999999999999999), I get a BigInteger and so I'd > expect that MathTool.random() would be able to return a BigInteger as well. > So I think we just need another clause which checks to see if Long isn't big > enough, and return a BigInteger instead. > (We might want to think about supporting BigDouble, too, but that's outside > the scope of this bug report.) -- This message was sent by Atlassian Jira (v8.20.7#820007) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@velocity.apache.org For additional commands, e-mail: dev-h...@velocity.apache.org