Skip to main content



      Home
Home » Modeling » TMF (Xtext) » [Xtend2] floats
[Xtend2] floats [message #718458] Wed, 24 August 2011 08:02 Go to next message
Eclipse UserFriend
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 08:10 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: [Xtend2] floats [message #753809 is a reply to message #718460] Fri, 28 October 2011 16:39 Go to previous messageGo to next message
Eclipse UserFriend
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 08:48 Go to previous messageGo to next message
Eclipse UserFriend
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 02:08 Go to previous messageGo to next message
Eclipse UserFriend
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 02:32 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

i guess the intended hook for this is StaticMethodsFeatureForTypeProvider

~Christian
Re: [Xtend2] floats [message #758322 is a reply to message #758149] Tue, 22 November 2011 13:05 Go to previous message
Eclipse UserFriend
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: Sun Jul 27 10:43:11 EDT 2025

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

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

Back to the top