Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 365393

Summary: [Xbase] NumberExtensions and IntegerExtensions
Product: [Modeling] TMF Reporter: Sven Efftinge <sven.efftinge>
Component: XtextAssignee: Jan Koehnlein <jan>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: jan, tmf.xtext-inbox
Version: 2.2.0Flags: sven.efftinge: juno+
Target Milestone: M4   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Sven Efftinge CLA 2011-12-02 02:40:05 EST
Define arithmetic operators for all kind of numbers including primitives and their wrappers as well as BigInteger and BigDecimal.

The primitive versions should be overloaded for the most commonly used cases.

IntegerExtensions needs methods for other Java operators like shifting.
Comment 1 Jan Koehnlein CLA 2011-12-02 09:47:12 EST
Integer and Double pushed to MASTER.
Now heading for BigInteger and BigDecimal
Comment 2 Jan Koehnlein CLA 2011-12-02 10:52:39 EST
Bound the following operators

  ! && || == !=                           for (boolean, boolean)
  - + ** * / % || && == != < <= > >= !    for (int, int) and (Integer, Number)
  - + ** * / % || && == != < <= > >= ! .. for (Integer, Number)
  - + ** * / == != < <= > >=              for (double, double)
  - + ** * /                              for (Double, Number)
  - + ** * /                              for (BigDecimal, BigDecimal)
  - + ** * / % || && !                    for (BigInteger, BigInteger)

Into the bargain, I've added the shift operators from Java as methods.

For the Object types, there is no need to override the default Comparable binding, as long as we don't plan to support comparing e.g. Double to BigInteger transparently.

I've skipped char, byte, short and float in this first shot. I've also skipped mixed primitve operations like int+double.
Comment 3 Jan Koehnlein CLA 2011-12-02 10:59:57 EST
Pushed to MASTER
Comment 4 Jan Koehnlein CLA 2011-12-02 12:18:40 EST
Found a problem with autoboxing. Generated Java code doesn't comple, because
  operator_plus(new Integer(a), 1) 
is ambiguos.
Comment 5 Jan Koehnlein CLA 2011-12-02 13:49:28 EST
The XbaseCompiler now explicitly boxes and unboxes primitives and their wrappers. 

Also converted bit operations on integer types into methods which are more suggestive to non-mathematicians ;-)
Comment 6 Karsten Thoms CLA 2017-09-19 17:36:18 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 7 Karsten Thoms CLA 2017-09-19 17:47:14 EDT
Closing all bugs that were set to RESOLVED before Neon.0