Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [xtend] Floating Point number and expressions with them
[xtend] Floating Point number and expressions with them [message #776164] Sat, 07 January 2012 12:36 Go to next message
Thomas Schindl is currently offline Thomas Schindl
Messages: 5296
Registered: July 2009
Senior Member
Hi,

here's a an method-definition is created to extrac the red value of a
hex-color definition (e.g. #FF0000).

---------8<---------
def red(String color) {
return Integer::valueOf(color.substring(1,3),16) /
Double::valueOf('255.0');
}
---------8<---------

You'll notice my first problem is that I'm unable to use floating point
literals (first problem) so i created a double using the valueOf-method.

The real problem though is that you are translating to Java code like this:

---------8<---------
public int red(final String color) {
String _substring = color.substring(1, 3);
Integer _valueOf = Integer.valueOf(_substring, 16);
Double _valueOf_1 = Double.valueOf("255.0");
int _operator_divide = IntegerExtensions.operator_divide(_valueOf,
_valueOf_1);
return _operator_divide;
}
---------8<---------
which means the result of this operation is an integer just like I would
have written x / 255.

To make the code act equal to java expressions one has to write:

---------8<---------
def red(String color) {
return Integer::valueOf(color.substring(1,3),16) as double /
Double::valueOf('255.0');
}
---------8<---------

I think it is incorrect to derive the result of an operation from the
first operand (at least in Java itself the result of an operation is in
the area of the biggest operand and not the first one which would be in
the original statement Double).

So here are my 2 problems:
a) Isn't there a shorter way to define a floating point number
b) Is it a bug or by design that the operation is happening in the area
of the first operand?

Tom
Re: [xtend] Floating Point number and expressions with them [message #776952 is a reply to message #776164] Mon, 09 January 2012 10:26 Go to previous message
Sebastian Zarnekow is currently offline Sebastian Zarnekow
Messages: 2809
Registered: July 2009
Senior Member
Hi Tom,

this should be solved in the latest version from Xtext HEAD. Stay tuned
for the next milestone.

Regards,
Sebastian
--
Need professional support for Eclipse Modeling?
Go visit: http://xtext.itemis.com


Am 07.01.12 18:36, schrieb Tom Schindl:
> Hi,
>
> here's a an method-definition is created to extrac the red value of a
> hex-color definition (e.g. #FF0000).
>
> ---------8<---------
> def red(String color) {
> return Integer::valueOf(color.substring(1,3),16) /
> Double::valueOf('255.0');
> }
> ---------8<---------
>
> You'll notice my first problem is that I'm unable to use floating point
> literals (first problem) so i created a double using the valueOf-method.
>
> The real problem though is that you are translating to Java code like this:
>
> ---------8<---------
> public int red(final String color) {
> String _substring = color.substring(1, 3);
> Integer _valueOf = Integer.valueOf(_substring, 16);
> Double _valueOf_1 = Double.valueOf("255.0");
> int _operator_divide = IntegerExtensions.operator_divide(_valueOf,
> _valueOf_1);
> return _operator_divide;
> }
> ---------8<---------
> which means the result of this operation is an integer just like I would
> have written x / 255.
>
> To make the code act equal to java expressions one has to write:
>
> ---------8<---------
> def red(String color) {
> return Integer::valueOf(color.substring(1,3),16) as double /
> Double::valueOf('255.0');
> }
> ---------8<---------
>
> I think it is incorrect to derive the result of an operation from the
> first operand (at least in Java itself the result of an operation is in
> the area of the biggest operand and not the first one which would be in
> the original statement Double).
>
> So here are my 2 problems:
> a) Isn't there a shorter way to define a floating point number
> b) Is it a bug or by design that the operation is happening in the area
> of the first operand?
>
> Tom
Previous Topic:syntax coloring
Next Topic:mwe2File
Goto Forum:
  


Current Time: Sat Aug 30 22:33:58 EDT 2014

Powered by FUDForum. Page generated in 0.01536 seconds