[
https://issues.apache.org/jira/browse/VELTOOLS-196?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claude Brisson resolved VELTOOLS-196.
-------------------------------------
Fix Version/s: 3.2
4.0
Assignee: Claude Brisson
Resolution: Fixed
> 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
> Assignee: Claude Brisson
> Priority: Minor
> Fix For: 3.2, 4.0
>
>
> 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.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]