# All files / src Relude_Decimal.bs.js

97.56% Statements 40/41
83.33% Branches 5/6
100% Functions 8/8
97.56% Lines 40/41

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96

    1x
    1x
    1x
    1x
    1x

    1x

    1x

    3x
    3x
    3x
    1x
    2x
    1x

    1x
    1x

    1x
    1x

    12x
    21x

    3x
    3x
    3x
    3x
    3x
    3x

    1x
    1x

    1x
    1x

    1x

    1x

    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x
    1x

     'use strict';

    var Curry = require("bs-platform/lib/js/curry.js");
    var Caml_int32 = require("bs-platform/lib/js/caml_int32.js");
    var Relude_Int = require("./Relude_Int.bs.js");
    var Relude_Array = require("./Relude_Array.bs.js");
    var Relude_String = require("./Relude_String.bs.js");

    function make(mantissa, exponent) {
      return /* Decimal */[
              mantissa,
              exponent
            ];
    }

    function fromInt(intValue) {
      return /* Decimal */[
              intValue,
              0
            ];
    }

    function show(param) {
      var exponent = param[1];
      var mantissa = param[0];
      if (exponent === 0) {
        return String(mantissa);
      } else if (exponent > 0) {
        Iif (mantissa === 0) {
          return "0";
        } else {
          var zeroes = Relude_String.repeat(exponent, "0");
          return String(mantissa) + zeroes;
        }
      } else {
        var match = Relude_String.splitAt(exponent, String(mantissa));
        return match[0] + ("." + match[1]);
      }
    }

    function tenToThePowerOfPositive(exponent) {
      return Relude_Array.foldLeft((function (acc, param) {
                      return Caml_int32.imul(10, acc);
                    }), 1)(Relude_Int.rangeAsArray(1, exponent + 1 | 0));
    }

    function normalize(param, param$1) {
      var exponentB = param$1[1];
      var exponentA = param[1];
      var exponentMin = Curry._2(Relude_Int.min, exponentA, exponentB);
      var newMantissaA = Caml_int32.imul(param[0], tenToThePowerOfPositive(exponentA - exponentMin | 0));
      var newMantissaB = Caml_int32.imul(param$1[0], tenToThePowerOfPositive(exponentB - exponentMin | 0));
      return /* tuple */[
              /* Decimal */[
                newMantissaA,
                exponentMin
              ],
              /* Decimal */[
                newMantissaB,
                exponentMin
              ],
              exponentMin
            ];
    }

    function add(lhs, rhs) {
      var match = normalize(lhs, rhs);
      return /* Decimal */[
              match[0][0] + match[1][0] | 0,
              match[2]
            ];
    }

    function subtract(lhs, rhs) {
      var match = normalize(lhs, rhs);
      return /* Decimal */[
              match[0][0] - match[1][0] | 0,
              match[2]
            ];
    }

    var $plus$dot$dot = add;

    var $neg$dot$dot = subtract;

    exports.make = make;
    exports.fromInt = fromInt;
    exports.show = show;
    exports.tenToThePowerOfPositive = tenToThePowerOfPositive;
    exports.normalize = normalize;
    exports.add = add;
    exports.$plus$dot$dot = $plus$dot$dot;
    exports.subtract = subtract;
    exports.$neg$dot$dot = $neg$dot$dot;
    /* Relude_Int Not a pure module */