Added make-polar.

This commit is contained in:
Abdulaziz Ghuloum 2008-07-15 23:13:59 -07:00
parent 195dc0ea45
commit 0ef81aa13e
5 changed files with 22 additions and 14 deletions

View File

@ -1,7 +1,6 @@
(library (ikarus not-yet-implemented)
(export
make-polar
bitwise-copy-bit-field bitwise-reverse-bit-field
bitwise-rotate-bit-field bitwise-if fxreverse-bit-field
fxrotate-bit-field
@ -17,7 +16,6 @@
string-upcase)
(import (except (ikarus)
make-polar
bitwise-copy-bit-field bitwise-reverse-bit-field
bitwise-rotate-bit-field bitwise-if fxreverse-bit-field
fxrotate-bit-field
@ -57,7 +55,6 @@
(not-yet
;;; should be implemented
string-downcase string-titlecase string-upcase
make-polar
bitwise-if
bitwise-rotate-bit-field bitwise-copy-bit-field bitwise-reverse-bit-field
fxreverse-bit-field fxrotate-bit-field

View File

@ -3620,11 +3620,11 @@
(library (ikarus complex-numbers)
(export make-rectangular $make-rectangular
(export make-rectangular $make-rectangular make-polar
real-part imag-part angle magnitude)
(import
(except (ikarus)
make-rectangular real-part imag-part angle magnitude)
(except (ikarus) make-rectangular make-polar
real-part imag-part angle magnitude)
(except (ikarus system $compnums) $make-rectangular))
(define ($make-rectangular r i)
@ -3655,6 +3655,16 @@
[else (err r)])]
[else (err i)]))
(define (make-polar mag angle)
(define who 'make-polar)
(unless (number? mag)
(die who "not a number" mag))
(unless (number? angle)
(die who "not a number" angle))
(make-rectangular
(* mag (cos angle))
(* mag (sin angle))))
(define magnitude
(lambda (x)
(cond

View File

@ -205,7 +205,7 @@
[(#\i)
(let ([real (do-dec-sn/ex sn ex (* ac (expt 10 exp)))])
(next im:done (make-rectangular 0.0 real)))]
[(#\e)
[(#\e #\E #\s #\S #\f #\F #\d #\D #\l #\L)
(if (fx=? r 10)
(next exponent r ex sn ac exp)
(fail))])
@ -218,7 +218,7 @@
[(#\i)
(let ([imag (do-dec-sn/ex sn ex (* ac (expt 10 exp)))])
(next im:done (make-rectangular real imag)))]
[(#\e)
[(#\e #\E #\s #\S #\f #\F #\d #\D #\l #\L)
(next im:exponent r real ex sn ac exp)])
(digit+ (r ex sn ac)
@ -238,7 +238,7 @@
(next im:sign r real ex -1))]
[(#\i)
(next im:done (make-rectangular 0 (do-sn/ex sn ex ac)))]
[(#\e)
[(#\e #\E #\s #\S #\f #\F #\d #\D #\l #\L)
(if (fx=? r 10)
(next exponent r ex sn ac 0)
(fail))])
@ -252,12 +252,12 @@
(fail))]
[(#\/)
(next im:ratio r real ex sn ac)]
[(#\e)
[(#\i)
(next im:done (make-rectangular real (do-sn/ex sn ex ac)))]
[(#\e #\E #\s #\S #\f #\F #\d #\D #\l #\L)
(if (fx=? r 10)
(next im:exponent r real ex sn ac 0)
(fail))]
[(#\i)
(next im:done (make-rectangular real (do-sn/ex sn ex ac)))])
(fail))])
(sign-i (r ex sn)
[(eof)

View File

@ -1 +1 @@
1539
1540

View File

@ -239,6 +239,7 @@
(test "-0e-0" -0.0)
(test "#d-0e-10-0e-0i" (make-rectangular -0.0 -0.0))
(test "-0.i" (make-rectangular 0.0 -0.0))
(test "#d#e-0.0f-0-.0s-0i" 0)
)