2019-10-09 13:13:56 +02:00
|
|
|
;;; math.el --- Math stuffs -*- lexical-binding: t -*-
|
2020-09-01 11:17:43 +02:00
|
|
|
|
2019-10-09 13:13:56 +02:00
|
|
|
;; Author: William Carroll <wpcarro@gmail.com>
|
2020-09-01 11:17:43 +02:00
|
|
|
;; Version: 0.0.1
|
|
|
|
;; Package-Requires: ((emacs "24.3"))
|
|
|
|
;; Homepage: https://user.git.corp.google.com/wpcarro/briefcase
|
2019-10-09 13:13:56 +02:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;; Containing some useful mathematical functions.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Dependencies
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(require 'maybe)
|
2020-09-02 16:23:46 +02:00
|
|
|
(require 'cl-lib)
|
2019-10-09 13:13:56 +02:00
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Constants
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defconst math-pi pi
|
2019-10-09 13:13:56 +02:00
|
|
|
"The number pi.")
|
|
|
|
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; Functions
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
;; TODO: Support all three arguments.
|
|
|
|
;; Int -> Int -> Int -> Boolean
|
2020-09-01 11:17:43 +02:00
|
|
|
(cl-defun math-triangle-of-power (&key base power result)
|
2019-10-09 13:13:56 +02:00
|
|
|
(cond
|
2020-08-31 15:59:48 +02:00
|
|
|
((maybe-somes? base power result)
|
2019-10-09 13:13:56 +02:00
|
|
|
(error "All three arguments should not be set"))
|
2020-08-31 15:59:48 +02:00
|
|
|
((maybe-somes? power result)
|
2019-10-09 13:13:56 +02:00
|
|
|
(message "power and result"))
|
2020-08-31 15:59:48 +02:00
|
|
|
((maybe-somes? base result)
|
2019-10-09 13:13:56 +02:00
|
|
|
(log result base))
|
2020-08-31 15:59:48 +02:00
|
|
|
((maybe-somes? base power)
|
2019-10-09 13:13:56 +02:00
|
|
|
(expt base power))
|
|
|
|
(t
|
|
|
|
(error "Two of the three arguments must be set"))))
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun math-mod (x y)
|
2019-10-09 13:13:56 +02:00
|
|
|
"Return X mod Y."
|
|
|
|
(mod x y))
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun math-exp (x y)
|
2019-10-09 13:13:56 +02:00
|
|
|
"Return X raised to the Y."
|
|
|
|
(expt x y))
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun math-round (x)
|
2019-10-09 13:13:56 +02:00
|
|
|
"Round X to nearest ones digit."
|
|
|
|
(round x))
|
|
|
|
|
2020-09-01 11:17:43 +02:00
|
|
|
(defun math-floor (x)
|
2019-10-09 13:13:56 +02:00
|
|
|
"Floor value X."
|
|
|
|
(floor x))
|
|
|
|
|
|
|
|
(provide 'math)
|
|
|
|
;;; math.el ends here
|