Don't forget that one of the goals of Valhalla is that you can declare
_your own_ value classes. While of course it is nice when broadly-useful
classes are provided by the JDK, and we intend to do so, this shouldn't
stop you from using your own BigRational type yourself today. (And if
it does, tell us why.)
On 8/3/2026 1:40 PM, David Alayachew wrote:
Perfect! That was exactly what I was looking for. Ty vm.
What would you say the chances of this making it in to the Standard Library
are?
Also, since BigRational is normalized, that means that it depends heavily
on reduction. That means the performance of gcd(), which I see you are
using, matters a ton. Would that be something you might specialize in order
to get good performance? I ask because I too started with gcd, but found it
to have some performance problems over time. Nothing bad, but this is a
number class, so that matters.
Thank you again, this is very insightful information!
On Mon, Aug 3, 2026, 11:20 AM Joseph D. Darcy<[email protected]> wrote:
Slide 39 of the slide deck [1] corresponding to the talk, gives a link
https://github.com/openjdk/valhalla/tree/type-classes/
to a Valhalla branch hosting numerical experiments with type classes
[2]. Some of the numerical prototypes there predate JavaOne. One of the
prototypes added after JavaOne was a BigRational type build on top of
BigIntegers:
https://github.com/openjdk/valhalla/blob/type-classes/src/java.base/share/classes/java/math/BigRational.java
Note a "Fraction" type would be different from a "Rational" type since
Fraction would presumably distinguish between "1/2" and "2/4" whereas a
Rational type would normalize these to 1/2.
-Joe
[1]
https://github.com/jddarcy/SpeakingArchive/blob/master/J1-2026-NumericalPaths.pdf
[2]https://github.com/openjdk/valhalla/compare/lworld...type-classes
On 8/2/2026 1:18 PM, David Alayachew wrote:
Hello @valhalla-dev<[email protected]>,
I just recently watched the video from JavaOne 2026 by Joe Darcy titled
"Paths to New Numeric Types on the Java Platform". Here is a link to it.
https://reddit.com/r/java/comments/1vdesc4/paths_to_new_numeric_types_on_the_java_platform/
My question is about Fractions.
The talk mentions that, if the mentioned features ever ship, we can
expect
to see Float16, amongst others, added to the JDK. Might we see Fractions
join that list?
I attempted my own version of this, titled BigNumber. Simply put, it was
a
class with a BigInteger numerator and a BigInteger denominator. Thus,
arbitrary precision until you need to cast/convert to another type. It
was
a really pleasant alternative to BigDecimal.
Here is the class --https://github.com/davidalayachew/BigNumber
I'm not at all proposing that my implementation is the right way to do
it.
Furthermore, I can make my own if/when this feature drops. But I wanted
to
ask if a fraction type like this might be added, as I suspect that this
would be a valuable tool for others too.
Thank you for your time and consideration.
David Alayachew