Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Operators for operations with java.lang.Number(How to define them?)
Operators for operations with java.lang.Number [message #1805077] Fri, 05 April 2019 12:36 Go to next message
Alexandre Lombard is currently offline Alexandre LombardFriend
Messages: 2
Registered: March 2019
Junior Member
Hello,

I have a question about the operators on standard types (plus, minus, etc.) taking java.lang.Number as parameter.

In DoubleExtensions, there are functions like this:

@Pure
public static double operator_plus(Double a, Number b) {
	return a + b.doubleValue();
}


It allows to use the plus operator to add a Double to a Number.
This function doesn't have an equivalent for Float, Integer, and the others but I'd like something like this in FloatExtensions:

@Pure
public static double operator_plus(Float a, Number b) {
	return a + b.doubleValue();
}


I tried to implement it myself in the DSL I'm working on, but when I do it, it fails when I try to use the + operator between a Float and a Number. It seems it's not able to use the good operator_plus I defined, as it tries to use another one (which won't work). However, if I use something else than Number (like AtomicDouble), the operator_plus I define works fine.

To be more precise when I have this (in an Xtend based language - SARL):

val f : Float = 0.0f
val l : Number = 0.0f
val res = f - l


I get this error:

Type mismatch: cannot convert from Number to byte for the l. Using a Double instead of a Float would work fine, but I want to be able to use operator_plus with a Float and a Number.

So my questions are, is there a reason for the operator_plus to not be defined between Float and Number in FloatExtensions? And, do you have any idea why it's trying to use another definition of the operator_plus? Is there something I should do to allow it to work?

[Updated on: Fri, 05 April 2019 12:38]

Report message to a moderator

Re: Operators for operations with java.lang.Number [message #1805078 is a reply to message #1805077] Fri, 05 April 2019 12:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
can you please open an issue for discussion at github.com/eclipse/xtext-lib
thanks


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Operators for operations with java.lang.Number [message #1805082 is a reply to message #1805078] Fri, 05 April 2019 13:18 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
https://github.com/eclipse/xtext-lib/issues/179

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Previous Topic:Accessing parser source correspondence for AST elements in standalone setup
Next Topic:Dynamic Elements of Language
Goto Forum:
  


Current Time: Wed Aug 21 16:33:48 GMT 2019

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

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

Back to the top