Integer root of floating point value

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.

Here’s another implementation for those interested in benchmarking:

https://github.com/perazz/fortran-bessels/blob/080119ab8fb296a95579b147aaf234388ffc97be/src/bessels_constants.f90#L878

1 Like

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.

1 Like

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

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

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
1 Like

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