You have several useful answers. I want to summarize what they saButy, and add a couple resources.
* You probably meant 9 ** <1/2>. Which will display 3. But it's a Num. It's not the right type if you care about accuracy. * A solution to get rationals right is built into Raku. See https://medium.com/@raiph_mellor/fixed-point-is-still-an-approximation-727c6facdbff But it won't work for `**` because it coerces to Num if the RHS is rational. * The full solution to getting math right is symbolic math. For Raku that means https://github.com/raydiak/Math-Symbolic Note that it includes features for roots. Note that we would all love to hear it works for you for equivalents of 9 ** <1/2> and/or 27 ** <1/3> In particular, not that the result *seems* right, but that it is the right type. (Int or Rat). Hth. On Thu, Jul 9, 2020 at 5:11 PM Tobias Boege <t...@taboege.de> wrote: > > On Thu, 09 Jul 2020, Aureliano Guedes wrote: > > Hi all, > > > > A quick question. > > > > This is expected? > > > > raku -e 'say 9 ** (1/3)' > > 2.080083823051904 > > > > > > Why do I'm asking this? > > I know about the computational floating problem and I also know that the > > Raku deal with rational whenever it is possible and store numbers as > > expressions (actually I don't know if there are more details). That's why > > 0.2 + 0.1 == 0.3 in Raku returns True whilst in other languages like > > Python, Perl5, and Ruby return False. > > > > Then, I was just playing around and I'd like to check if it is expected. > > > > I for one expected it. The equation 0.1 + 0.2 == 0.3 uses the Rat type in > Raku, which stores rational numbers as exact fractions of numerator and > denominator, avoiding the floating point inaccuracies you mention, and > hence making equality comparisons trustworthy. > > The number 9 ** (1/3) is not rational and in general exponentiation with a > fractional power might not produce a rational number, so exact representation > via Rat is out of the question. Therefore Rakudo does the computation with > Num, which are inexact floating point values again. > > Now, there are effective ways to represent algebraic numbers like 9 ** (1/3) > in such a way that you can do arithmetic with them, but I'm not aware of any > implementation of that available to Raku. For someone with enough tuits, > I think this [1] can serve as a sort of high-level manual for creating such > a module. In terms of ready-made non-Raku packages, I only know of CGAL [2], > which provides a clean and even (template-)parametric interface to real > algebraic numbers. In fact, I might have a try at NativeCall'ing it this > evening. > > Best, > Tobias > > [1] https://math.stackexchange.com/a/3144516 > [2] https://www.cgal.org/ > > -- > "There's an old saying: Don't change anything... ever!" -- Mr. Monk