Number problems
Anders Peterson
anders at optimatika.se
Sun Sep 29 09:26:13 UTC 2019
Hi,
A ComplexNumber class that will be efficient to use is a common example of what Valhalla will enable.
In order to be able to write math code that is common for any/all “numbers” then the various implementations must have something in common - like a common interface.
Inline classes cannot extends any other class - they cannot extend java.lang.Number.
Can existing final classes that only extend Object be converted to inline classes? Even if that will be possible the classes Double, Integer, Long… cannot be converted to inline since they extend Number.
I’m the author of a Java math (linear algebra) library, and very interested in the capabilities I believe Valhalla will bring. I plan to have a Valhalla-enabled version of my library as soon as it’s released, and I’m eager to make adaptations already now that will simply future changes.
Are there any plans to create a new interface that (re)defines java.lang.Number?
Then perhaps a second interface, that extends that first one, and further declares methods like add/subtract/multiply/divide/… Most (all) classes that today extend java.lang.Number should be able to implement this interface AND it can be used to create new numerical inline classes like ComplexNumber.
In my library today there is such an interface but there are difficulties regarding how to interact and coexist with java.lang.Number and the various primitive types. Some of these challenges would go away if (something like) the interfaces I invented was defined in “Java” itself.
/Anders
More information about the valhalla-spec-comments
mailing list