Hey,
sorry for taking my time with the response. While indeed conforming, I've added a separate code path for ratios. I'm conditioning on the integer length (like SBCL does).
static cl_object ecl_log1_ratio(cl_object x) { cl_object num = x->ratio.num; cl_object den = x->ratio.den; if (ecl_integer_length(num) != ecl_integer_length(den)) { return ecl_minus(ecl_log1(num), ecl_log1(den)); } else { return ecl_log1_fixnum(x); } }
Thanks all for the input. The change is now submitted as a merge request against develop (and will be part of the next release).
Best regards, Daniel
-- Daniel Kochmański ;; aka jackdaniel | Przemyśl, Poland TurtleWare - Daniel Kochmański | www.turtleware.eu
"Be the change that you wish to see in the world." - Mahatma Gandhi
------- Original Message ------- On Sunday, July 10th, 2022 at 5:39 PM, James Cloos cloos@jhcloos.com wrote:
i should have realized this even before noticing ecl's limitation for logs of ratios, but at least i finally did....
since i'monly using log to find the exponent for an arbitrary precision replacement for format's ~e, it works to truncate first.
so i ended up with this:
(defun ilog (n &optional (base nil base-p)) "return floor of base b log of n" (let ((s (if (< n 1) -1 1)) (trunc-n (truncate (if (< n 1) (/ n) n)))) (floor (* s (if base-p (log trunc-n base) (log trunc-n))))))
One could use let* and then test s when choosing between n and (/ n), but i choose instead to let the compiler optimize the two calls to (< n 1).
that makes my ~e replacement work exactly as desired on all lisps i've tried.
(I have a ~// function which chooses output baed on the arg's type, with ratios done via that print-e-significant-digits function and everything else using write.)
-JimC
James Cloos cloos@jhcloos.com OpenPGP: 0x997A9F17ED7DAEA6