Skip to content

Commit

Permalink
abs on complex numbers #34
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 16, 2025
1 parent 04a7f77 commit 427a15e
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![npm](https://img.shields.io/badge/npm-1.0.0%E2%80%93beta.19-blue.svg)](https://www.npmjs.com/package/@jcubic/lips)
![1.0.0 Complete](https://img.shields.io/github/milestones/progress-percent/jcubic/lips/1?label=1.0.0%20Complete)
[![Build and test](https://github.com/jcubic/lips/actions/workflows/build.yaml/badge.svg?branch=devel&event=push)](https://github.com/jcubic/lips/actions/workflows/build.yaml)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&57335eab53c7df00260611523df184d0)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Coverage Status](https://coveralls.io/repos/github/jcubic/lips/badge.svg?branch=devel&d4dc10c03c3665f14904416f753ddc68)](https://coveralls.io/github/jcubic/lips?branch=devel)
[![Join Gitter Chat](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jcubic/lips)
![NPM Download Count](https://img.shields.io/npm/dm/@jcubic/lips)
![JSDelivr Download count](https://img.shields.io/jsdelivr/npm/hm/@jcubic/lips)
Expand Down
5 changes: 3 additions & 2 deletions bin/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ if (options.version || options.V) {
return [LSymbol(key), ...values];
}));
bootstrap(interp).then(function() {
// Scheme can access JS global.output
return run('(for-each (lambda (x) (write x) (newline)) output)', interp, options.d || options.dynamic);
});
} else if (options.e || options.eval) {
Expand Down Expand Up @@ -574,12 +575,12 @@ function run_repl(err, rl) {
let resolve;
const brackets_re = /\x1b\[(200|201)~/g;
// we use promise loop to fix issue when copy paste list of S-Expression
const is_emacs = process.env.EMACS || process.env.INSIDE_EMACS;
let prev_eval = Promise.resolve();
if (process.stdin.isTTY) {
if (process.stdin.isTTY || is_emacs) {
rl.prompt();
}
let prev_line;
const is_emacs = process.env.INSIDE_EMACS;
function is_brackets_mode() {
return !!cmd.match(brackets_re);
}
Expand Down
17 changes: 13 additions & 4 deletions dist/lips.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions dist/lips.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/lips.esm.min.js

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions dist/lips.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/lips.min.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/lips.js
Original file line number Diff line number Diff line change
Expand Up @@ -6351,6 +6351,12 @@ LComplex.prototype.constant = function(im, re) {
enumerable(this, '__type__', 'complex');
};
// -------------------------------------------------------------------------
LComplex.prototype.abs = function() {
const im = this.__im__.abs();
const re = this.__re__.abs();
return LComplex({ im, re });
};
// -------------------------------------------------------------------------
LComplex.prototype.serialize = function() {
return {
re: this.__re__,
Expand Down
27 changes: 27 additions & 0 deletions tests/numbers.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1113,3 +1113,30 @@
(t.is (to.throw (op? 1.2)) #t)
(t.is (to.throw (op? 1.2)) #t))
'(even? odd?))))

(test "numbers: abs"
(lambda (t)
(let ((specs '((10 10)
(0.5 0.5)
(-0.5 0.5)
(-10 10)
(-1/2 1/2)
(-10-10i 10+10i)
(-10+10i 10+10i)
(10-10i 10+10i)
(10+10i 10+10i)
(-1/2-1/2i 1/2+1/2i)
(-1/2+1/2i 1/2+1/2i)
(1/2-1/2i 1/2+1/2i)
(-0.5-0.5i 0.5+0.5i)
(-0.5+0.5i 0.5+0.5i)
(0.5-0.5i 0.5+0.5i)
(0.5+0.5i 0.5+0.5i)
(-nan.0 +nan.0)
(+nan.0 +nan.0)
(-inf.0 +inf.0)
(+inf.0 +inf.0))))
(for-each (lambda (lst)
(t.is (abs (car lst))
(cadr lst)))
specs))))

0 comments on commit 427a15e

Please sign in to comment.