Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface Math

Math (Native)

The ThoughtAsylum library includes a set of extensions to the standard Math object.

Hierarchy

  • Math

Index

Methods

TA_frac

  • TA_frac(p_numValue: number): number
  • Get the fractional part of a number. JavaScript frustratingly does imperfect calculations with decimals, and so this function jumps through some hoops to give a higher precision answer than the JavaScript mathematics functions alone might provide. e.g. try alert(12.345 - Math.floor(12.345)); and check the result! The function accounts for differing separators between locales, zero values, negative values, and values missing leading zeros.

    Parameters

    • p_numValue: number

      the value that the fractional part should be returned for.

      // Example
      alert("12.354 = " + Math.TA_frac(12.345));
      

    Returns number

TA_integerToRoman

  • TA_integerToRoman(p_intValue: number, p_bupperCase?: Boolean): string
  • Convert an integer to a Roman numeral. Returns the number as a roman numeral string.

    Parameters

    • p_intValue: number

      the number to convert.

    • Optional p_bupperCase: Boolean

      defaults to true and will output as upper case, otherwise as lower case.

      // Example
      alert(Math.TA_integerToRoman(2021, false));
      

    Returns string

TA_isOneIn

  • TA_isOneIn(p_intMax: number): Boolean
  • For a random integer up to the one specified returns true if the number generated is a one. The idea is to return true/false on the chance of something occurring being one in, and the number specified. The function generates an integer between one and the specified maximum value, inclusive, and if the result is 1 it will return true, otherwise it returns false.

    Parameters

    • p_intMax: number

      the maximum value of the random integer the function will generate.

      // Example
      alert(Math.TA_isOneIn(6));
      

    Returns Boolean

TA_randInt

  • TA_randInt(p_intMin: number, p_intMax: number): number
  • Generate a random integer value between a minimum and maximum value (inclusive). Parameters should be integers and will be rounded down if not.

    Parameters

    • p_intMin: number

      minimum value of the random integer.

    • p_intMax: number

      maximum value of the random integer.

      // Example
      alert(Math.TA_randInt(1, 10));
      

    Returns number