UNPKG

money-ts

Version:

TypeScript library for type-safe and lossless encoding and manipulation of world currencies and precious metals

29 lines 1.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var natural = require("./Natural"); var rational = require("./Rational"); var nonZeroInteger = require("./NonZeroInteger"); var newtype_ts_1 = require("newtype-ts"); function fromRational(r) { return nonZeroInteger.fromInteger(r[0]).map(function (n) { return [n, r[1]]; }); } exports.fromRational = fromRational; exports.reduce = newtype_ts_1.unsafeCoerce(rational.reduce); exports.add = newtype_ts_1.unsafeCoerce(rational.add); exports.mul = newtype_ts_1.unsafeCoerce(rational.mul); exports.one = newtype_ts_1.unsafeCoerce(rational.one); function sub(x, y) { return fromRational(rational.sub(x, y)); } exports.sub = sub; exports.div = newtype_ts_1.unsafeCoerce(rational.div); function inverse(x) { var d = x[1]; var n = nonZeroInteger.abs(x[0]); return nonZeroInteger.isPositive(x[0]) ? [d, n] : [natural.negate(d), n]; } exports.inverse = inverse; exports.setoid = rational.setoid; exports.ord = rational.ord; exports.show = rational.show; //# sourceMappingURL=NonZeroRational.js.map