1 |
;; Calculator for GNU Emacs, part II [calc-frac.el] |
;;; calc-frac.el --- fraction functions for Calc |
2 |
|
|
3 |
;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
;; Copyright (C) 1990, 1991, 1992, 1993, 2001 Free Software Foundation, Inc. |
|
;; Written by Dave Gillespie, daveg@synaptics.com. |
|
4 |
|
|
5 |
;; This file is part of GNU Emacs. |
;; Author: David Gillespie <daveg@synaptics.com> |
6 |
|
;; Maintainer: Colin Walters <walters@debian.org> |
7 |
|
|
8 |
;; GNU Emacs is distributed in the hope that it will be useful, |
;; GNU Emacs is distributed in the hope that it will be useful, |
9 |
;; but WITHOUT ANY WARRANTY. No author or distributor |
;; but WITHOUT ANY WARRANTY. No author or distributor |
20 |
;; file named COPYING. Among other things, the copyright notice |
;; file named COPYING. Among other things, the copyright notice |
21 |
;; and this notice must be preserved on all copies. |
;; and this notice must be preserved on all copies. |
22 |
|
|
23 |
|
;;; Commentary: |
24 |
|
|
25 |
|
;;; Code: |
26 |
|
|
27 |
;; This file is autoloaded from calc-ext.el. |
;; This file is autoloaded from calc-ext.el. |
28 |
(require 'calc-ext) |
(require 'calc-ext) |
31 |
|
|
32 |
(defun calc-Need-calc-frac () nil) |
(defun calc-Need-calc-frac () nil) |
33 |
|
|
|
|
|
34 |
(defun calc-fdiv (arg) |
(defun calc-fdiv (arg) |
35 |
(interactive "P") |
(interactive "P") |
36 |
(calc-slow-wrapper |
(calc-slow-wrapper |
51 |
|
|
52 |
|
|
53 |
(defun calc-over-notation (fmt) |
(defun calc-over-notation (fmt) |
54 |
(interactive "sFraction separator (:, ::, /, //, :/): ") |
(interactive |
55 |
|
(list |
56 |
|
(completing-read "Fraction separator: " (mapcar (lambda (s) |
57 |
|
(cons s 0)) |
58 |
|
'(":" "::" "/" "//" ":/")) |
59 |
|
nil t))) |
60 |
(calc-wrapper |
(calc-wrapper |
61 |
(if (string-match "\\`\\([^ 0-9][^ 0-9]?\\)[0-9]*\\'" fmt) |
(if (string-match "\\`\\([^ 0-9][^ 0-9]?\\)[0-9]*\\'" fmt) |
62 |
(let ((n nil)) |
(let ((n nil)) |
65 |
fmt (math-match-substring fmt 1))) |
fmt (math-match-substring fmt 1))) |
66 |
(if (eq n 0) (error "Bad denominator")) |
(if (eq n 0) (error "Bad denominator")) |
67 |
(calc-change-mode 'calc-frac-format (list fmt n) t)) |
(calc-change-mode 'calc-frac-format (list fmt n) t)) |
68 |
(error "Bad fraction separator format.")))) |
(error "Bad fraction separator format")))) |
69 |
|
|
70 |
(defun calc-slash-notation (n) |
(defun calc-slash-notation (n) |
71 |
(interactive "P") |
(interactive "P") |
78 |
(calc-wrapper |
(calc-wrapper |
79 |
(calc-change-mode 'calc-prefer-frac n nil t) |
(calc-change-mode 'calc-prefer-frac n nil t) |
80 |
(message (if calc-prefer-frac |
(message (if calc-prefer-frac |
81 |
"Integer division will now generate fractions." |
"Integer division will now generate fractions" |
82 |
"Integer division will now generate floating-point results.")))) |
"Integer division will now generate floating-point results")))) |
|
|
|
|
|
|
|
|
|
83 |
|
|
84 |
|
|
85 |
;;;; Fractions. |
;;;; Fractions. |
134 |
(nth 1 b)))) |
(nth 1 b)))) |
135 |
|
|
136 |
|
|
|
|
|
|
|
|
137 |
;;; Convert a real value to fractional form. [T R I; T R F] [Public] |
;;; Convert a real value to fractional form. [T R I; T R F] [Public] |
138 |
(defun calcFunc-frac (a &optional tol) |
(defun calcFunc-frac (a &optional tol) |
139 |
(or tol (setq tol 0)) |
(or tol (setq tol 0)) |