DKL9 GitList
Repositories
DKL9 home
rtensor
Code
Commits
Branches
Tags
Search
Tree:
117473e
Branches
Tags
master
rtensor
types
basic.js
Refactor towards a working QuickJS version
dkl9
commited
117473e
at 2023-196 12:46:40
basic.js
Blame
History
Raw
"use strict"; export class BasicNumber { constructor() {} sub(z) { return this.add(z.neg()); } div(z) { return this.mul(z.recip()); } pow(z) { return this.ln().mul(z).exp(); } log(z) { return this.ln().div(z.ln()); } isNeg() { return this.lt(this.constructor.zero()); } rangeTo(b) { const al = Math.ceil(b.sub(this).mag() + 1); const ud = b.sub(this).dir(); return (new Array(al)).fill(0).map((_z, i) => this.add(ud.mul(this.constructor.ify(i)))); } dir() { return this.mag().eq(0) ? this.constructor.one() : this.div(this.constructor.ify(this.mag())); } } // because the prototype fields are nonenumerable argh BasicNumber.keys = ["sub", "div", "pow", "log", "isNeg", "rangeTo", "dir"]; ["zero", "one", "add", "neg", "mul", "recip", "exp", "ln", "sqrt", "sin", "cos", "asin", "acos", "atan", "eq", "lt", "mag", "floor"].forEach(o => BasicNumber.prototype[o] = function() { throw `${o} not defined for current number type`; });