Functional Weave
Code in Python

math.fractional-power@1.0.0

vectors.json

2,908 bytes · view raw

[
  {
    "name": "a whole power that is exact in decimal",
    "args": [
      "1.1",
      2,
      1
    ],
    "expect": "1.210000000000"
  },
  {
    "name": "square root of two",
    "args": [
      "2",
      1,
      2
    ],
    "expect": "1.414213562373"
  },
  {
    "name": "monthly factor of a 19.9% annual rate",
    "args": [
      "1.199",
      1,
      12
    ],
    "expect": "1.015238935953"
  },
  {
    "name": "31 days of a 19.9% APR on a 365-day year",
    "args": [
      "1.199",
      31,
      365
    ],
    "expect": "1.015533447820"
  },
  {
    "name": "a negative exponent discounts: 1/1.05^10",
    "args": [
      "1.05",
      -10,
      1
    ],
    "expect": "0.613913253541"
  },
  {
    "name": "three halves power",
    "args": [
      "1.5",
      3,
      2
    ],
    "expect": "1.837117307087"
  },
  {
    "name": "a root of a number below one",
    "args": [
      "0.5",
      1,
      3
    ],
    "expect": "0.793700525984"
  },
  {
    "name": "one to any power is one",
    "args": [
      "1",
      7,
      365
    ],
    "expect": "1.000000000000"
  },
  {
    "name": "reciprocal of ten",
    "args": [
      "10",
      -1,
      1
    ],
    "expect": "0.100000000000"
  },
  {
    "name": "30 years of monthly compounding at 5.4%",
    "args": [
      "1.0045",
      360,
      1
    ],
    "expect": "5.034760199014"
  },
  {
    "name": "a payday-style 1000% APR over 30 days",
    "args": [
      "11",
      30,
      365
    ],
    "expect": "1.217850333327"
  },
  {
    "name": "a base with the full 18 decimal places",
    "args": [
      "1.000000000000000001",
      1000,
      1
    ],
    "expect": "1.000000000000"
  },
  {
    "name": "fraction not in lowest terms gives the same answer",
    "args": [
      "1.199",
      62,
      730
    ],
    "expect": "1.015533447820"
  },
  {
    "name": "zero base is refused",
    "args": [
      "0",
      1,
      2
    ],
    "expectError": "base must be greater than zero"
  },
  {
    "name": "a negative base is refused",
    "args": [
      "-1",
      1,
      1
    ],
    "expectError": "base must be a positive decimal with at most 18 places"
  },
  {
    "name": "more than 18 decimal places is refused",
    "args": [
      "1.1234567890123456789",
      1,
      1
    ],
    "expectError": "base must be a positive decimal with at most 18 places"
  },
  {
    "name": "exponent denominator of zero",
    "args": [
      "2",
      1,
      0
    ],
    "expectError": "exponentDenominator must be between 1 and 100000"
  },
  {
    "name": "exponent numerator out of range",
    "args": [
      "2",
      100001,
      1
    ],
    "expectError": "exponentNumerator must be between -100000 and 100000"
  },
  {
    "name": "a result beyond 2^512 is refused",
    "args": [
      "10",
      200,
      1
    ],
    "expectError": "fractional power result too large"
  }
]