# Integer root of floating point value

**URL:** <https://fortran-lang.discourse.group/t/integer-root-of-floating-point-value/5239>\
**Category:** Uncategorized\
**Created:** [February 20, 2023, 11:14am UTC](https://fortran-lang.discourse.group/t/integer-root-of-floating-point-value/5239 "2023-02-20T11:14:46Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [February 23, 2023, 8:11pm UTC](https://fortran-lang.discourse.group/t/integer-root-of-floating-point-value/5239/28 "2023-02-23T20:11:15Z")

</div>

> [@mecej4](#):
>
> A good working solution for the cube root problem would probably require a good way of generating sufficiently close first approximations without resorting to calling `exp` or `log`.

When one does these things by hand, the first step is to divide the exponent by 3 for a cube root (2 for a square root, etc). If more accuracy is needed, then extracting maybe the high-order 4 bits of the mantissa and using that in a lookup table would be sufficient.

---

<div class="post-metadata">

**Author:** ![FedericoPerini](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/federicoperini/32/1750_2.png) [@FedericoPerini](https://fortran-lang.discourse.group/u/FedericoPerini)\
**Post date:** [February 23, 2023, 8:27pm UTC](https://fortran-lang.discourse.group/t/integer-root-of-floating-point-value/5239/29 "2023-02-23T20:27:40Z")

</div>

> [@mecej4](#):
>
> A good working solution

Here’s another implementation for those interested in benchmarking:

[https://github.com/perazz/fortran-bessels/blob/080119ab8fb296a95579b147aaf234388ffc97be/src/bessels\_constants.f90#L878](https://github.com/perazz/fortran-bessels/blob/080119ab8fb296a95579b147aaf234388ffc97be/src/bessels_constants.f90#L878)

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [February 23, 2023, 10:36pm UTC](https://fortran-lang.discourse.group/t/integer-root-of-floating-point-value/5239/30 "2023-02-23T22:36:48Z")

</div>

> [@kargl](#):
>
> It would only be missing leading to those that do not learn the language. Of course, having provided patches for gfortran for 2+ decades, I can safely say most users seem to have an aversion to documentation.

Fair enough for already existing features/syntax: they are there, and we have to do with them as they are. But when it comes to introduce a new syntax, it can be a good idea to look at what it means elsewhere. `^` is a widely used convention to denote exponentiation/superscript in many languages or math oriented softwares/utilities.

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [February 24, 2023, 2:32pm UTC](https://fortran-lang.discourse.group/t/integer-root-of-floating-point-value/5239/31 "2023-02-24T14:32:47Z")

</div>

Summary of suggestions for an operator based nth integer root (in order of appearance), with my comments :

```auto
x = y ** n ! reminder of nth power ;)

y = x // n ! would be possible, although // has a fully different meaning in another context
y = x */ n ! 2-characters operator, like for the nth power
y = x ^ n ! denotes the nth power in many other languages rather then the nth root
y = n .throot. x ! reversed order ?
y = x .root. n ! would make sense if (x .pow. n) was existing
y = x ^/ n ! could make sense if y^n was adopted as an alternative to y**n

```

---

<div class="post-metadata">

**Author:** ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)\
**Post date:** [February 24, 2023, 2:43pm UTC](https://fortran-lang.discourse.group/t/integer-root-of-floating-point-value/5239/32 "2023-02-24T14:43:48Z")

</div>

Not to discourage the exploration, but I’ll just note that this is part of a paper adding the missing operations suggested by IEEE, and `**` is the only operator we currently use to support them.

| IEEE-754 Operation | Fortran Operation | Status |
| --- | --- | --- |
| exp | EXP | available |
| expm1 | EXPM1 | proposed |
| exp2 | 2\*\*x | available |
| exp2m1 | EXP2M1 | proposed |
| exp10 | 10\*\*x | available |
| exp10m1 | EXP10M1 | proposed |
| log | LOG | available |
| log2 | LOG2 | proposed |
| log10 | LOG10 | available |
| logp1 | LOGP1 | proposed |
| log2p1 | LOG2P1 | proposed |
| log10p1 | LOG10P1 | proposed |
| hypot | HYPOT | available |
| rsqrt | RSQRT | proposed |
| compound | COMPOUND | proposed |
| rootn | ROOTN | proposed |
| pown | x\*\*n | available |
| pow | x\*\*y | available |
| powr | POWR | proposed |
| sin | SIN | available |
| cos | COS | available |
| tan | TAN | available |
| sinPi | SINPI | available |
| cosPi | COSPI | available |
| tanPi | TANPI | available |
| asin | ASIN | available |
| acos | ACOS | available |
| atan | ATAN | available |
| atan2 | ATAN2 | available |
| asinPi | ASINPI | available |
| acosPi | ACOSPI | available |
| atanPi | ATANPI | available |
| atan2Pi | ATAN2PI | available |
| sinh | SINH | available |
| cosh | COSH | available |
| tanh | TANH | available |
| asinh | ASINH | available |
| acosh | ACOSH | available |
| atanh | ATANH | available |

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [February 24, 2023, 4:24pm UTC](https://fortran-lang.discourse.group/t/integer-root-of-floating-point-value/5239/33 "2023-02-24T16:24:32Z")

</div>

> [@everythingfunctional](#):
>
> Not to discourage the exploration, but I’ll just note that this is part of a paper adding the missing operations suggested by IEEE, and `**` is the only operator we currently use to support them.

Got it… Just in case it’s still possible to consider it…

[Previous page](https://fortran-lang.discourse.group/t/integer-root-of-floating-point-value/5239.md?page=1)
