How to use the @phensley/decimal.Decimal function in @phensley/decimal

To help you get started, we’ve selected a few @phensley/decimal examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github phensley / cldr-engine / packages / cldr-compiler / src / cli / generator / code / plurals.ts View on Github external
const generate = (sample: string): string[] => {
  if (sample.indexOf('~') === -1) {
    return [sample];
  }
  const res: string[] = [];
  const [_s, _e] = sample.split('~');
  let s = new Decimal(_s);
  const e = new Decimal(_e);
  let incr = DecimalConstants.ONE;
  if (s.scale() > 0) {
    incr = incr.movePoint(-s.scale());
  }
  while (s.compare(e) !== 0) {
    res.push(s.toString());
    s = s.add(incr);
  }
  // console.log(`${s.toString()} ${e.toString()} incr ${incr.toString()}`;
  return res;
};
github phensley / cldr-engine / packages / cldr-compiler / src / cli / generator / code / plurals.ts View on Github external
const generate = (sample: string): string[] => {
  if (sample.indexOf('~') === -1) {
    return [sample];
  }
  const res: string[] = [];
  const [_s, _e] = sample.split('~');
  let s = new Decimal(_s);
  const e = new Decimal(_e);
  let incr = DecimalConstants.ONE;
  if (s.scale() > 0) {
    incr = incr.movePoint(-s.scale());
  }
  while (s.compare(e) !== 0) {
    res.push(s.toString());
    s = s.add(incr);
  }
  // console.log(`${s.toString()} ${e.toString()} incr ${incr.toString()}`;
  return res;
};
github phensley / cldr-engine / packages / cldr-ext-rbnf / src / rbnf.ts View on Github external
RuleType,
  RBNFInst,
  RBNFRule,
  SubLeftInst,
} from './rbnftypes';
import { binarySearch } from './utils';

// Divisors based on the number of integer digits in the number being formatted.
// A 2-digit number's divisor will be '1e1', 3-digit '1e2' and so on.
// This table stops just past the largest base value found in the RBNF dataset.
const DIVISORS: Decimal[] = [0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
  .map(e => new Decimal(`1e${e}`));

const { ONE, ZERO } = DecimalConstants;
const MINUS_ONE = ONE.negate();
const TEN = new Decimal(10);

type IntegerSubInst = ApplyLeftRuleInst
  | ApplyLeft2RuleInst
  | ApplyLeft2NumFormatInst
  | ApplyLeftNumFormatInst
  | SubLeftInst;

export interface RBNFSymbols {
  decimal: string;
  nan: string;
  infinity: string;
}

export type RBNFDecimalFormatter =
  (pattern: string, n: Decimal) => string;
github phensley / cldr-engine / packages / cldr-ext-rbnf / src / rbnf.ts View on Github external
    this.numbers = numbers ? numbers.split('_').map((n: string) => new Decimal(n)) : [];
    for (const id of Object.keys(locales)) {
github phensley / cldr-engine / packages / cldr-core / src / internals / schema.ts View on Github external
const time = (n: [number, number]) =>
  new Decimal(n[0]).add(new Decimal(n[1]).movePoint(-9));
github phensley / cldr-engine / packages / messageformat / src / evaluation / args.ts View on Github external
export const asdecimal = (arg: MessageArg): Decimal => {
  switch (typeof arg) {
    case 'string':
      try {
        return new Decimal(arg);
      } catch (e) {
        return DecimalConstants.NAN;
      }
    case 'number':
      return new Decimal(arg);
    case 'boolean':
      return arg ? DecimalConstants.ONE : DecimalConstants.ZERO;
    case 'object':
      if (arg instanceof Decimal) {
        return arg;
      }
      break;
  }
  return DecimalConstants.NAN;
};