mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-05-21 06:39:17 +02:00
Adding support for complex literals in exponential format.
This commit is contained in:
parent
9b0f9c73f2
commit
44c643c7cf
2 changed files with 28 additions and 7 deletions
27
sexp.c
27
sexp.c
|
@ -2320,16 +2320,37 @@ sexp sexp_read_float_tail (sexp ctx, sexp in, double whole, int negp) {
|
|||
for (; c==SEXP_PLACEHOLDER_DIGIT; c=sexp_read_char(ctx, in), scale*=0.1)
|
||||
val += sexp_placeholder_digit_value(10)*scale;
|
||||
#endif
|
||||
val += whole;
|
||||
if (negp) val *= -1;
|
||||
if (is_precision_indicator(c)) {
|
||||
c2 = sexp_read_char(ctx, in);
|
||||
if (c2 != '+') sexp_push_char(ctx, c2, in);
|
||||
exponent = sexp_read_number(ctx, in, 10);
|
||||
if (sexp_exceptionp(exponent)) return exponent;
|
||||
if (sexp_exceptionp(exponent)) {
|
||||
sexp_gc_release1(ctx);
|
||||
return exponent;
|
||||
}
|
||||
#if SEXP_USE_COMPLEX
|
||||
if (sexp_complexp(exponent)) {
|
||||
res = exponent;
|
||||
exponent = (sexp_complex_real(res) == SEXP_ZERO ? sexp_complex_imag(res) : sexp_complex_real(res));
|
||||
}
|
||||
#endif
|
||||
e = (sexp_fixnump(exponent) ? sexp_unbox_fixnum(exponent)
|
||||
: sexp_flonump(exponent) ? sexp_flonum_value(exponent) : 0.0);
|
||||
#if SEXP_USE_COMPLEX
|
||||
if (sexp_complexp(res)) {
|
||||
if (sexp_complex_real(res) == SEXP_ZERO) {
|
||||
sexp_complex_imag(res) = sexp_make_flonum(ctx, val * pow(10, e));
|
||||
} else {
|
||||
sexp_complex_real(res) = sexp_make_flonum(ctx, val * pow(10, e));
|
||||
}
|
||||
sexp_gc_release1(ctx);
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
val = (whole + val) * pow(10, e);
|
||||
if (negp) val *= -1;
|
||||
if (e != 0.0) val *= pow(10, e);
|
||||
#if SEXP_USE_FLONUMS
|
||||
res = sexp_make_flonum(ctx, val);
|
||||
#else
|
||||
|
|
|
@ -1546,10 +1546,10 @@
|
|||
;; Decimal-notation complex numbers (rectangular notation)
|
||||
("1.0+2i" (make-rectangular 1.0 2) "1.0+2.0i" "1.0+2i" "1.+2i" "1.+2.i")
|
||||
("1+2.0i" (make-rectangular 1 2.0) "1.0+2.0i" "1+2.0i" "1.+2.i" "1+2.i")
|
||||
;; ("1e2+1.0i" (make-rectangular 100.0 1.0) "100.0+1.0i" "100.+1.i")
|
||||
;; ("1s2+1.0i" (make-rectangular 100.0 1.0) "100.0+1.0i" "100.+1.i")
|
||||
;; ("1.0+1e2i" (make-rectangular 1.0 100.0) "1.0+100.0i" "1.+100.i")
|
||||
;; ("1.0+1s2i" (make-rectangular 1.0 100.0) "1.0+100.0i" "1.+100.i")
|
||||
("1e2+1.0i" (make-rectangular 100.0 1.0) "100.0+1.0i" "100.+1.i")
|
||||
("1s2+1.0i" (make-rectangular 100.0 1.0) "100.0+1.0i" "100.+1.i")
|
||||
("1.0+1e2i" (make-rectangular 1.0 100.0) "1.0+100.0i" "1.+100.i")
|
||||
("1.0+1s2i" (make-rectangular 1.0 100.0) "1.0+100.0i" "1.+100.i")
|
||||
;; Fractional complex numbers (rectangular notation)
|
||||
("1/2+3/4i" (make-rectangular (/ 1 2) (/ 3 4)))
|
||||
;; Mixed fractional/decimal notation complex numbers (rectangular notation)
|
||||
|
|
Loading…
Add table
Reference in a new issue