Support #1039
Rename iroot?
Description
Some time ago we renamed ILog2
to FloorLog2
, and some other similar functions.
There is still a function iroot
. Should this be renamed?
If so, to what? FloorRoot
, TruncRoot
, IntRoot
?
History
#1 Updated by John Abbott about 7 years ago
- Status changed from New to In Progress
- % Done changed from 0 to 10
Currently iroot
computes the truncated integer part of the real root.
For instance iroot(-30,3)
gives -3
as its result.
If we want to call it FloorRoot
then we have to change the definition when the result is negative.
Internally, the function which does the work is mpz_root
.
We could just leave things as they are. Comments? Ideas?
#2 Updated by Anna Maria Bigatti about 7 years ago
John Abbott wrote:
Currently
iroot
computes the truncated integer part of the real root.
For instanceiroot(-30,3)
gives-3
as its result.If we want to call it
FloorRoot
then we have to change the definition when the result is negative.
We can make a new function FloorRoot
(which does what it says).
Then make iroot
obsolescent saying that it may be substituted by sign(a)*FloorRoot(abs(a), n)
.
Internally, the function which does the work is
mpz_root
.
does it truncate?
do you think it might be costly to convert it in "floor"?
We could just leave things as they are. Comments? Ideas?
I'd rather change iroot
#3 Updated by Anna Maria Bigatti about 7 years ago
- % Done changed from 10 to 20
"better safe than sorry"
the easiest and safest is to give an error when the input is negative.
Even though "Floor" is pretty clear, the risk of misusing FloorRoot
with negative input is high.
#4 Updated by John Abbott about 7 years ago
There is also a fn called IsExactIroot(ans, N,r)
. It returns a bool
, and puts into ans
the truncated integer part of the r
-th root of N
.
What should this fn be called? And what should its definition be?
If we rename iroot
to FloorRoot
, and limit it to roots of non-negative integers then probably the same limitations should apply to this fn. The name could be IsExactFloorRoot
, though that is rather ugly.
#5 Updated by John Abbott about 5 years ago
- Assignee set to John Abbott
- Target version changed from CoCoALib-1.0 to CoCoALib-0.99700
Even though GMP allows negative inputs to its mpz_root
function, I like the idea of limiting the number whose root is to be found to being non-negative... well, I do find negative numbers "antipatico" ;-)
So a combination of the suggestions in comments 2, 3 and 4 seems reasonable.
#6 Updated by John Abbott about 5 years ago
- Status changed from In Progress to Resolved
- % Done changed from 20 to 70
I have changed the names into FloorRoot
and IsExactFloorRoot
.
Added iroot
to obsolescent.H/C
.
Test and examples are OK. Must still change doc.
#7 Updated by John Abbott over 4 years ago
- Status changed from Resolved to Closed
- Target version changed from CoCoALib-0.99700 to CoCoALib-0.99650 November 2019
- % Done changed from 70 to 100
- Estimated time set to 2.34 h
This has apparently all been done (incl. doc, tests, CVS).
No complaints, so closing.