Issue Details (XML | Word | Printable)

Key: GROOVY-1944
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Jochen Theodorou
Reporter: Michael Baehr
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
groovy

isCase implementation for BigDecimals needed based on numerical value only

Created: 16/Jun/07 03:27 AM   Updated: 01/Jul/07 10:32 AM
Component/s: groovy-jdk
Affects Version/s: None
Fix Version/s: 1.1-beta-2

Time Tracking:
Not Specified

File Attachments: 1. Text File GROOVY-1944.patch (2 kB)



 Description  « Hide
BigDecimals carry both a numerical value and a precision (scale).

In Groovy, when BigDecimals are compared, only the numerical value is taken into account, but isCase() uses both value and scale.

This should be consistent.

assert 0.5 == 0.50000 // works
switch(0.5) {
case 0.50000: println "match" // doesn't match
}



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Michael Baehr added a comment - 16/Jun/07 02:35 PM
It looks like a simple method in DefaultGroovyMethods.java is all that is needed:

public static boolean isCase(Number caseValue, Number switchValue) {
return NumberMath.compareTo(caseValue, switchValue)==0;
}

The attached patch contains this method and adds some tests to SwitchWithDifferentTypesTest.groovy.


Jochen Theodorou added a comment - 01/Jul/07 10:32 AM
applied