Open jcubic opened 4 years ago
Arithmetic error:
;; Returns the arithmetic, geometric, and
;; harmonic means of a nested list of numbers
(define (means ton)
(letrec*
((mean
(lambda (f g)
(f (/ (sum g ton) n))))
(sum
(lambda (g ton)
(if (null? ton)
(+)
(if (number? ton)
(g ton)
(+ (sum g (car ton))
(sum g (cdr ton)))))))
(n (sum (lambda (x) 1) ton)))
(values (mean values values)
(mean exp log)
(mean / /))))
Note that evaluating (means '(3 (1 4)))
returns three values: 8/3, 2.28942848510666 (approximately), and 36/19.
LIPS devel returns:
8/3
2.2894284851066633
8/3
Function (means '(3 (1 4)))
is fixed the problem was that (/ 2)
was returning 2
and it was even in doc string. According to spec it should return 1/2
.
Hi,
Not sure if this is supposed to be working already (I see expt
is not marked in your checklist), but anyway - (expt 1.5 0)
and (expt 2 3.0)
return an error saying that LIPS can't convert BigInt to number...
@jpellegrini thanks I will make sure to add those to unit tests when will work on that function.
fixed the simple case and Started adding tests for bigint + float combination, but still rational need some work:
lips> (expt 1/2 2)
1/4
lips> (expt 2 1/2)
2/1
there is a need to add different root calculations (I'm not sure if Scheme has something like this out of the box, it may be useful to expose).
And also added an exception when invoking expt
on complex numbers since this will require more work, need to think how to handle trigonometry functions, that are required to calculate power operation on complex numbers.
there is a need to add different root calculations (I'm not sure if Scheme has something like this out of the box, it may be useful to expose).
R7RS has only square roots... I usually do (expt x 1/n)
for the n-th root.
And also added an exception when invoking expt on complex numbers since this will require more work, need to think how to handle trigonometry functions, that are required to calculate power operation on complex numbers.
Maybe (expt x y)
could be implemented as (exp (* (log x) y))
, if you already have log
for complexes?
And (log z)
, with z
complex, would be
REAL: (log (magnitude z))
IMAG: (angle z)
Maybe
(expt x y)
could be implemented as(exp (* (log x) y))
, if you already havelog
for complexes?
See PR #247
And I see you already have implemented complex log
...
@jpellegrini expt
was fully implemented and fully tested. It will be released in the next beta version.
It matches the implementation of Kawa and doesn't have rounding errors when the power is an integer.
TODO:
(make-rectangular 1/2 2/4)
(/ 10+10i 10+2i)
works in Kawa(Lips convert to Float)+nan.0+5.0i
3.0+inf.0i
#i1/2+2/4i
->(exact->inexact 1/2+2/4i)
.10e+10i
.#b
#o
#x
#d
)#b1/100
#b100+100i
#e
#i
exact inexact literals that do conversion#b#x
#x#b
replace in tokenizer(1/4 == 0.25)#i#b1/100
inexact rational binary#e1e-1000
or#e1.2e-1000
+nan.0
and-nan.0
return by parser#[ieoxb]
string->number
sqrt
abs
/
+
-
*
Bugs