close Warning: Can't synchronize with repository "(default)" (The repository directory has changed, you should resynchronize the repository with: trac-admin $ENV repository resync '(default)'). Look in the Trac log for more information.

source: branches/f4grobner/rational-field.lisp@ 4452

Last change on this file since 4452 was 4387, checked in by Marek Rychlik, 8 years ago
File size: 3.4 KB
RevLine 
[4269]1;;; -*- Mode: Lisp -*-
2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3;;;
4;;; Copyright (C) 1999, 2002, 2009, 2015 Marek Rychlik <rychlik@u.arizona.edu>
5;;;
6;;; This program is free software; you can redistribute it and/or modify
7;;; it under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 2 of the License, or
9;;; (at your option) any later version.
10;;;
11;;; This program is distributed in the hope that it will be useful,
12;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with this program; if not, write to the Free Software
18;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19;;;
20;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21
[4325]22(in-package "RING")
[4269]23
[4341]24(defclass rational-field (field)
[4315]25 ((value :initarg :value :initform 0 :accessor rational-field-value :type rational))
[4269]26 (:documentation "An object representing an integer.")
27 )
28
29(defmethod print-object ((self rational-field) stream)
30 (print-unreadable-object (self stream :type t :identity t)
31 (with-accessors ((value rational-field-value))
32 self
33 (format stream "VALUE=~A" value))))
34
35(defmethod multiply-by ((self rational-field) (other rational-field))
36 (with-slots (value)
37 self
38 (with-slots ((other-value value))
39 other
40 (setf value (* value other-value))))
41 self)
42
43(defmethod divide-by ((self rational-field) (other rational-field))
44 (with-slots (value)
45 self
46 (with-slots ((other-value value))
47 other
48 (setf value (/ value other-value))))
49 self)
50
51(defmethod add-to ((self rational-field) (other rational-field))
52 (with-slots (value)
53 self
54 (with-slots ((other-value value))
55 other
56 (setf value (+ value other-value))))
57 self)
58
59(defmethod subtract-from ((self rational-field) (other rational-field))
60 (with-slots (value)
61 self
62 (with-slots ((other-value value))
63 other
64 (setf value (- value other-value))))
65 self)
66
67(defmethod unary-minus ((self rational-field))
68 (with-slots (value)
69 self
70 (setf value (- value)))
71 self)
72
73(defmethod unary-inverse ((self rational-field))
74 (with-slots (value)
75 self
[4272]76 (setf value (/ value)))
[4271]77 self)
[4269]78
79(defmethod universal-zerop ((self rational-field))
80 (with-slots (value)
81 self
82 (zerop value)))
83
84(defmethod universal-equalp ((self rational-field) (other rational-field))
85 (with-slots (value)
86 self
87 (with-slots ((other-value value))
88 other
89 (= value other-value))))
90
91(defmethod ->sexp ((self rational-field) &optional vars)
92 (declare (ignore vars))
93 (rational-field-value self))
[4308]94
[4321]95(defparameter *rational-field-zero* (make-instance 'rational-field :value 0))
96(defparameter *rational-field-unit* (make-instance 'rational-field :value 1))
[4316]97
[4308]98(defmethod make-zero-for ((object rational-field))
[4318]99 (copy-instance *rational-field-zero*))
[4308]100
101(defmethod make-unit-for ((object rational-field))
[4318]102 (copy-instance *rational-field-unit*))
[4356]103
[4361]104(defmethod universal-gcd ((self rational-field) (other rational-field))
105 (copy-instance *rational-field-unit*))
[4362]106
Note: See TracBrowser for help on using the repository browser.