Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Functions

  • add<T>(a: T, b: T, message?: string): T
  • Add 2 integers (unsigned or signed)

    example
    const res = SafeMath.add(1, 2);

    // code here is not executed if the calculation above overflows/underflows

    Type Parameters

    • T

    Parameters

    • a: T

      unsigned or signed integer

    • b: T

      unsigned or signed integer

    • message: string = ''

      message that will be logged if the calculation reverts

    Returns T

    reverts if overflow/underflow, result otherwise

  • div<T>(a: T, b: T, message?: string): T
  • Divide 2 integers (unsigned or signed)

    example
    const res = SafeMath.div(1, 2);

    // code here is not executed if the calculation above overflows/underflows

    Type Parameters

    • T

    Parameters

    • a: T

      unsigned or signed integer

    • b: T

      unsigned or signed integer

    • message: string = ''

      message that will be logged if the calculation reverts

    Returns T

    reverts if overflow/underflow, result otherwise

  • mod<T>(a: T, b: T, message?: string): T
  • Calculate the modulo of 2 integers (unsigned or signed)

    example
    const res = SafeMath.mod(10, 2);

    // code here is not executed if the calculation above overflows/underflows

    Type Parameters

    • T

    Parameters

    • a: T

      unsigned or signed integer

    • b: T

      unsigned or signed integer

    • message: string = ''

      message that will be logged if the calculation reverts

    Returns T

    reverts if overflow/underflow, result otherwise

  • mul<T>(a: T, b: T, message?: string): T
  • Multiply 2 integers (unsigned or signed)

    example
    const res = SafeMath.mul(1, 2);

    // code here is not executed if the calculation above overflows/underflows

    Type Parameters

    • T

    Parameters

    • a: T

      unsigned or signed integer

    • b: T

      unsigned or signed integer

    • message: string = ''

      message that will be logged if the calculation reverts

    Returns T

    reverts if overflow/underflow, result otherwise

  • sub<T>(a: T, b: T, message?: string): T
  • Subtract 2 integers (unsigned or signed)

    example
    const res = SafeMath.sub(1, 2);

    // code here is not executed if the calculation above overflows/underflows

    Type Parameters

    • T

    Parameters

    • a: T

      unsigned or signed integer

    • b: T

      unsigned or signed integer

    • message: string = ''

      message that will be logged if the calculation reverts

    Returns T

    reverts if overflow/underflow, result otherwise

  • Try to add 2 integers (unsigned or signed)

    example
    const res = SafeMath.tryAdd(1, 2);

    if (!res.error) {
    System.Log('1 + 2 = ' + c.value.toString());
    } else {
    System.log('could not add');
    }

    Type Parameters

    • T

    Parameters

    • a: T

      unsigned or signed integer

    • b: T

      unsigned or signed integer

    Returns SafeInteger<T>

    SafeInteger

  • Try to divide 2 integers (unsigned or signed)

    example
    const res = SafeMath.tryDiv(2, 1);

    if (!res.error) {
    System.Log('2 / 1 = ' + c.value.toString());
    } else {
    System.log('could not divide');
    }

    Type Parameters

    • T

    Parameters

    • a: T

      unsigned or signed integer

    • b: T

      unsigned or signed integer

    Returns SafeInteger<T>

    SafeInteger

  • Try to calculate the modulo of 2 integers (unsigned or signed)

    example
    const res = SafeMath.tryMod(2, 1);

    if (!res.error) {
    System.Log('2 % 1 = ' + c.value.toString());
    } else {
    System.log('could not calculate modulo');
    }

    Type Parameters

    • T

    Parameters

    • a: T

      unsigned or signed integer

    • b: T

      unsigned or signed integer

    Returns SafeInteger<T>

    SafeInteger

  • Try to multiply 2 integers (unsigned or signed)

    example
    const res = SafeMath.tryMul(2, 1);

    if (!res.error) {
    System.Log('2 * 1 = ' + c.value.toString());
    } else {
    System.log('could not multiply');
    }

    Type Parameters

    • T

    Parameters

    • a: T

      unsigned or signed integer

    • b: T

      unsigned or signed integer

    Returns SafeInteger<T>

    SafeInteger

  • Try to subtract 2 integers (unsigned or signed)

    example
    const res = SafeMath.trySub(2, 1);

    if (!res.error) {
    System.Log('2 - 1 = ' + c.value.toString());
    } else {
    System.log('could not subtract');
    }

    Type Parameters

    • T

    Parameters

    • a: T

      unsigned or signed integer

    • b: T

      unsigned or signed integer

    Returns SafeInteger<T>

    SafeInteger

Generated using TypeDoc