help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

math (was: Re: not good proposal: "C-z <letter>" reserved for users)


From: Emanuel Berg
Subject: math (was: Re: not good proposal: "C-z <letter>" reserved for users)
Date: Sat, 13 Feb 2021 15:55:52 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> Jean Louis wrote:
>
>> (defun pct-of-number-in-total (number total)
>>  "Return the percentage that NUMBER represents in a TOTAL."
>>  (let* ((percent (/ (float total) 100))
>>         (percentage (/ (float number) percent)))
>>    percentage))
>
> (defun percent (n d)
>   (let ((pct (* 100 (/ n d 1.0))))
>     (message "%.1f%%" pct)))
>
> (percent 13973 204612) ; 6.8%

The 1.0 and (float) just don't look good. Maybe one should do
it onee time and be done with it.

(defun // (n d)
  (/ n d 1.0) )
;; (// 8 256) ; 0.03125
;; (/  8 256) ; 0

But maybe then people would think it (//) would correspond
somehow to **, or `expt'...

(defalias '** #'expt)

and, it would require a lot of `require's from all over... but
then one would get away with the unidiomatic 1.0s for good!

https://dataswamp.org/~incal/emacs-init/math.el

-- 
underground experts united
http://user.it.uu.se/~embe8573
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]