all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* percent-change
@ 2023-05-11 13:35 Emanuel Berg
  2023-05-13 13:37 ` percent-change Ruijie Yu via Users list for the GNU Emacs text editor
  2023-05-13 15:16 ` percent-change Yuri Khan
  0 siblings, 2 replies; 9+ messages in thread
From: Emanuel Berg @ 2023-05-11 13:35 UTC (permalink / raw)
  To: help-gnu-emacs

Take a look at this, see examples for intended bahvior.
This was more difficult than I imagined, maybe there is some
simpler way to do it?

Otherwise it just shows once again that computing something
and writing a program to compute it are not the same ...

;;; -*- lexical-binding: t -*-
;;
;; this file:
;;   https://dataswamp.org/~incal/emacs-init/math.el

(defun percent-change (from to)
  (let ((dist (abs (- to from))))
    (if (zerop dist)
        0
      (let ((change (abs (/ dist from 0.01))))
        (if (< from to)
            change
          (* -1 change) )))))

;; (percent-change   1  2) ;  100
;; (percent-change   1  1) ;    0
;; (percent-change   1  0) ; -100
;; (percent-change   1 -1) ; -200

;; (percent-change   0  1) ;  1.0e+INF
;; (percent-change   0  0) ;  0
;; (percent-change   0 -1) ; -1.0e+INF

;; (percent-change  -1  1) ;  200
;; (percent-change  -1  0) ;  100
;; (percent-change  -1 -1) ;    0
;; (percent-change  -1 -2) ; -100

-- 
underground experts united
https://dataswamp.org/~incal




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-05-15  2:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-11 13:35 percent-change Emanuel Berg
2023-05-13 13:37 ` percent-change Ruijie Yu via Users list for the GNU Emacs text editor
2023-05-13 14:00   ` percent-change Emanuel Berg
2023-05-13 14:06   ` percent-change Emanuel Berg
2023-05-13 15:16 ` percent-change Yuri Khan
2023-05-13 15:58   ` percent-change Emanuel Berg
2023-05-13 16:04   ` percent-change Emanuel Berg
2023-05-14 14:29     ` percent-change Yuri Khan
2023-05-15  2:54       ` percent-change Emanuel Berg

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.