Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtend2] floats
[Xtend2] floats [message #718458] Wed, 24 August 2011 12:02 Go to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 333
Registered: July 2009
Senior Member
Hi there,

does Xtend2 not support any float primitive type? I could not write any
float literals like 0.0 or 23.789, however, I can assign floats to
variables which I got from somewhere else.

A workaround is
"23.789".float
and defining a getFloat function that uses Float.getValue(String).

There should be something better, should it not?

Cheers,
Hauke
Re: [Xtend2] floats [message #718460 is a reply to message #718458] Wed, 24 August 2011 12:10 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

i guess it is intent not to support floats in Xtend.
feel free to file an enhancement request.
btw wasn't everything a real (double) in Xtend1

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xtend2] floats [message #753809 is a reply to message #718460] Fri, 28 October 2011 20:39 Go to previous messageGo to next message
Thomas Trocha is currently offline Thomas TrochaFriend
Messages: 14
Registered: October 2011
Junior Member
Here is a blogpost how to integrate doubles in xbase:

http koehnlein.blogspot.com/2011/07/extending-xbase.html
(I'm not allowed to post links therefore this link looks that destroyed Very Happy)

Btw: I really can not understand why you build the best piece of software and do not include decimals,
Re: [Xtend2] floats [message #753849 is a reply to message #753809] Sat, 29 October 2011 12:48 Go to previous messageGo to next message
Meinte Boersma is currently offline Meinte BoersmaFriend
Messages: 434
Registered: July 2009
Location: Leiden, Netherlands
Senior Member
Well, decimals are included since the JVM type's available. There's just not a literal for it, but neither is there for a lot of other stuff (regular expressions, RGB colors, etc.) - you have to use your workaround for those as well, which is not at all painful because of the short, inferred syntax. I think the decision what literals to provide in Xtend2 has mostly to do with what is useful for generation purposes and I don't see that for decimals.

Re: [Xtend2] floats [message #758149 is a reply to message #753849] Tue, 22 November 2011 07:08 Go to previous messageGo to next message
Hauke Fuhrmann is currently offline Hauke FuhrmannFriend
Messages: 333
Registered: July 2009
Senior Member
Am 29.10.2011 14:48, schrieb Meinte Boersma:
> Well, decimals are included since the JVM type's available. There's just
> not a literal for it.

Maybe it would help a lot if it were possible to do infix operator
overloading also by extension methods. I.e. I understand so far you have
to define a method for the class you want to overload, e.g.

class Float{
public Float _operator_multiply(final Float other){
return this * other;
}
}

However, we cannot change the basic datatype classes, so it would be
nice I could simply write extensions like

class FloatExtensions{
public Float _operator_multiply(final Float e1, final Float e2){
return e1 * e2;
}
}

Which I then can use in my Xtend simply the same:

@Inject
extension FloatExtension

def function(Float a, Float b){
return a._operator_multiply(b)
}

Hence, it would be nice if in this case operator overloading would work
such I could write a * b instead.

Is this a proper feature request or are there arguments against?

Cheers,
Hauke
Re: [Xtend2] floats [message #758151 is a reply to message #758149] Tue, 22 November 2011 07:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14664
Registered: July 2009
Senior Member
Hi,

i guess the intended hook for this is StaticMethodsFeatureForTypeProvider

~Christian


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: [Xtend2] floats [message #758322 is a reply to message #758149] Tue, 22 November 2011 18:05 Go to previous message
Sebastian Zarnekow is currently offline Sebastian ZarnekowFriend
Messages: 3118
Registered: July 2009
Senior Member
Hi,

if you use the proper naming scheme (operator_multiply instead of
_operator_multiply) everything works.

@Inject
extension Floats

def doSomething(float a, float b) {
a * b
}

def client(Float a, Float b) {
a * b
}

==

public class Floats {

public float operator_multiply(float a, float b) {
return a * b;
}

}

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

On Tue, 22 Nov 2011 08:08:46 +0100, Hauke Fuhrmann
<hauke.fuhrmann@funkwerk-it.com> wrote:

> Am 29.10.2011 14:48, schrieb Meinte Boersma:
>> Well, decimals are included since the JVM type's available. There's just
>> not a literal for it.
>
> Maybe it would help a lot if it were possible to do infix operator
> overloading also by extension methods. I.e. I understand so far you have
> to define a method for the class you want to overload, e.g.
>
> class Float{
> public Float _operator_multiply(final Float other){
> return this * other;
> }
> }
>
> However, we cannot change the basic datatype classes, so it would be
> nice I could simply write extensions like
>
> class FloatExtensions{
> public Float _operator_multiply(final Float e1, final Float e2){
> return e1 * e2;
> }
> }
>
> Which I then can use in my Xtend simply the same:
>
> @Inject
> extension FloatExtension
>
> def function(Float a, Float b){
> return a._operator_multiply(b)
> }
>
> Hence, it would be nice if in this case operator overloading would work
> such I could write a * b instead.
>
> Is this a proper feature request or are there arguments against?
>
> Cheers,
> Hauke
Previous Topic:JVM model inferrer for non-xbase models
Next Topic:DomainCompiler in Xtext 2.1
Goto Forum:
  


Current Time: Tue Apr 16 07:24:59 GMT 2024

Powered by FUDForum. Page generated in 0.17621 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top