Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0-beta-4
-
None
-
All
Description
This issue is from the recent groovy-dev list discussion concering the use of BigDecimal as the default numeric type for literals with a decimal point. Also, numeric literal suffixes should be supported to specify the type.
In the discussion, James Strachan said:
-----------------------------------------------------------------
- BigDecimal is the default type for any floating point number
literals. For non-decimals we can choose the best size (Integer, Long,
BigInteger based on the length of the number)
- folks can use B (big decimal) postfix to be explict or use D (double)
or F (float) for more explicit control.
- to call typesafe methods of lower type (double, float) then you have
to either use the doubleValue() or floatValue() methods or cast.
foo(float p)
{ ... }x = 1.234
foo( (float) x )
foo( x.floatValue() )
unless
x = 1.234F
foo
------------------------------------------------------------------
Concerning:
>For non-decimals we can choose the best size (Integer, Long,
>BigInteger based on the length of the number)
Should we automatically choose the size or use suffixes (or both)?
B BigInteger (also means BigDecimal for literals with a dot)
I Integer
L Long
Attachments
Attachments
Issue Links
- depends upon
-
GROOVY-251 Lexer does not recognize .1 as a numeric literal
- Closed
- is depended upon by
-
GROOVY-271 Groovy does not support floating point constants with exponents
- Closed
-
GROOVY-274 Negate (-) does not work for types other than Integer, Double
- Closed
-
GROOVY-275 Allows assignment of a value to a numeric type which is too large for it to hold
- Closed
-
GROOVY-339 Problem coercing 7/3 to double
- Closed
-
GROOVY-273 ClassGenration for numeric literal types other than Double and Integer
- Closed
-
GROOVY-281 Improve error message when a matching constructor cannot be found at runtime
- Closed
- is duplicated by
-
GROOVY-270 should Groovy allow constants of the form 1L?
- Closed