Skip to content

Commit da65806

Browse files
committed
Hypercomplex plus
1 parent ab0a7d0 commit da65806

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

TODO.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* avcodec\_receive\_frame
1414
* avcodec\_send\_packet
1515
* codec deprecated (ffmpeg.c: 271, 377, 417)
16+
* Wayland support
1617
* check new lintian tag required
1718
* argmin, argmax
1819
* argwhere (mask coordinates)

aiscm/hypercomplex.scm

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<hypercomplex<>>
2626
<hypercomplex<float>> <meta<hypercomplex<float>>> <hypercomplex<float<single>>> <meta<hypercomplex<float<single>>>>
2727
<hypercomplex<double>> <meta<hypercomplex<double>>> <hypercomplex<float<double>>> <meta<hypercomplex<float<double>>>>)
28-
#:re-export (real-part imag-part equal?))
28+
#:re-export (real-part imag-part equal? +))
2929

3030

3131
(define-class <hypercomplex> ()
@@ -74,3 +74,17 @@
7474
(hypercomplex (reduce coerce #f (cons b (base a)))))
7575
(define-method (coerce (a <meta<scalar>>) (b <meta<hypercomplex<>>>))
7676
(hypercomplex (reduce coerce #f (cons a (base b)))))
77+
78+
(define-method (+ (a <hypercomplex<>>) (b <hypercomplex<>>))
79+
(hypercomplex (+ (real-part a) (real-part b))
80+
(+ (imag-part a) (imag-part b))
81+
(+ (jmag-part a) (jmag-part b))
82+
(+ (kmag-part a) (kmag-part b))))
83+
(define-method (+ (a <hypercomplex<>>) (b <complex<>>))
84+
(hypercomplex (+ (real-part a) (real-part b)) (+ (imag-part a) (imag-part b)) (jmag-part a) (kmag-part a)))
85+
(define-method (+ (a <complex<>>) (b <hypercomplex<>>))
86+
(hypercomplex (+ (real-part a) (real-part b)) (+ (imag-part a) (imag-part b)) (jmag-part b) (kmag-part b)))
87+
(define-method (+ (a <hypercomplex<>>) (b <scalar>))
88+
(hypercomplex (+ (real-part a) b) (imag-part a) (jmag-part a) (kmag-part a)))
89+
(define-method (+ (a <scalar>) (b <hypercomplex<>>))
90+
(hypercomplex (+ a (real-part b)) (imag-part b) (jmag-part b) (kmag-part b)))

tests/test_hypercomplex.scm

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,21 @@
9595
(test-eq "coerce real and hypercomplex type"
9696
(hypercomplex <double>) (coerce <double> (hypercomplex <float>))))
9797

98+
(test-group "hypercomplex plus"
99+
(test-equal "hypercomplex plus hypercomplex"
100+
(make-hypercomplex 2.0 3.0 5.0 7.0) ((jit (list (hypercomplex <float>) (hypercomplex <float>)) +)
101+
(make-hypercomplex 1 2 3 4) (make-hypercomplex 1 1 2 3)))
102+
(test-equal "hypercomplex plus complex"
103+
(make-hypercomplex 2.0 3.0 5.0 7.0) ((jit (list (hypercomplex <float>) (complex <float>)) +)
104+
(make-hypercomplex 1 2 5 7) 1+i))
105+
(test-equal "complex plus hypercomplex"
106+
(make-hypercomplex 2.0 3.0 5.0 7.0) ((jit (list (complex <float>) (hypercomplex <float>)) +)
107+
1+i (make-hypercomplex 1 2 5 7)))
108+
(test-equal "hypercomplex plus real"
109+
(make-hypercomplex 2.0 3.0 5.0 7.0) ((jit (list (hypercomplex <float>) <float>) +)
110+
(make-hypercomplex 1 3 5 7) 1))
111+
(test-equal "real plus hypercomplex"
112+
(make-hypercomplex 2.0 3.0 5.0 7.0) ((jit (list <float> (hypercomplex <float>)) +)
113+
1 (make-hypercomplex 1 3 5 7))))
114+
98115
(test-end "aiscm hypercomplex")

tmux.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ tmux select-pane -t0
55
tmux send-keys "make repl -j 4" C-m
66
tmux select-pane -t1
77
tmux send-keys "cd tests" C-m
8-
tmux send-keys "./guard.sh core" C-m
8+
tmux send-keys "./guard.sh hypercomplex" C-m
99
tmux select-pane -t2
1010
tmux send-keys "nvim" C-m
1111
sleep 1

0 commit comments

Comments
 (0)