UNPKG

@epicallan/money-ts

Version:

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

31 lines 1.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.show = exports.Ord = exports.Eq = exports.inverse = exports.div = exports.sub = exports.one = exports.mul = exports.add = exports.reduce = exports.fromRational = void 0; var O = require("fp-ts/Option"); var natural = require("./Natural"); var rational = require("./Rational"); var nonZeroInteger = require("./NonZeroInteger"); var function_1 = require("fp-ts/function"); function fromRational(r) { return function_1.pipe(nonZeroInteger.fromInteger(r[0]), O.map(function (n) { return [n, r[1]]; })); } exports.fromRational = fromRational; exports.reduce = function_1.unsafeCoerce(rational.reduce); exports.add = function_1.unsafeCoerce(rational.add); exports.mul = function_1.unsafeCoerce(rational.mul); exports.one = function_1.unsafeCoerce(rational.one); function sub(x, y) { return fromRational(rational.sub(x, y)); } exports.sub = sub; exports.div = function_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.Eq = rational.Eq; exports.Ord = rational.Ord; exports.show = rational.show; //# sourceMappingURL=NonZeroRational.js.map