Skip to main content



      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 08:36 Go to next message
Eclipse UserFriend
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 08:38] by Moderator

Re: Operators for operations with java.lang.Number [message #1805078 is a reply to message #1805077] Fri, 05 April 2019 08:43 Go to previous messageGo to next message
Eclipse UserFriend
can you please open an issue for discussion at github.com/eclipse/xtext-lib
thanks
Re: Operators for operations with java.lang.Number [message #1805082 is a reply to message #1805078] Fri, 05 April 2019 09:18 Go to previous message
Eclipse UserFriend
https://github.com/eclipse/xtext-lib/issues/179
Previous Topic:Accessing parser source correspondence for AST elements in standalone setup
Next Topic:Dynamic Elements of Language
Goto Forum:
  


Current Time: Mon Mar 24 07:16:10 EDT 2025

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

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

Back to the top