Class MathFunctions

java.lang.Object
com.scriptbasic.utility.functions.MathFunctions

public class MathFunctions
extends java.lang.Object
This class contains static methods that are place holders to register the methods of the class java.lang.Math for the BASIC programs. If the documentation of the method does not specify different then the method in this class can be invoked directly from a BASIC program and does exactly the same as the method of the same name in the class java.lang.Math.

When a method accepts Number arguments it means that the BASIC can call the function with integer or with floating point arguments.

Author:
Peter Verhas
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static java.math.RoundingMode roundingMode
    Rounding mode used by round function
  • Method Summary

    Modifier and Type Method Description
    static java.lang.Number abs​(java.lang.Number x)  
    static double acos​(double x)  
    static double asin​(double x)  
    static double atan​(double x)  
    static double atan2​(double x, double y)  
    static double cbrt​(double x)  
    static double ceil​(double x)  
    static double copySign​(double magnitude, double sign)  
    static double cos​(double x)  
    static double cosh​(double x)  
    static double exp​(double a)  
    static double expm1​(double x)  
    static java.lang.Double floatF​(java.lang.Object s)
    Convert a value to floating point.
    static double floor​(double x)  
    static java.lang.Long getExponent​(double d)  
    static double hypot​(double x, double y)  
    static double IEEEremainder​(double f1, double f2)  
    static java.lang.Long integer​(java.lang.Object s)
    Convert a value to integer.
    static double log​(double x)  
    static double log10​(double x)  
    static double log1p​(double x)  
    static java.lang.Number max​(java.lang.Number a, java.lang.Number b)  
    static java.lang.Number min​(java.lang.Number a, java.lang.Number b)  
    static double pow​(double a, double b)  
    static double random()  
    static double rint​(double a)  
    static java.lang.Number round​(double value, java.lang.Integer numdecimalplaces)
    Returns a number rounded to a specified number of decimal places.
    static double scalb​(double d, int scaleFactor)  
    static double signum​(double d)  
    static double sin​(double x)  
    static double sinh​(double x)  
    static double sqrt​(double a)  
    static double tan​(double x)  
    static double tanh​(double x)  
    static double toDegrees​(double angrad)  
    static double toRadians​(double angdeg)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • roundingMode

      public static java.math.RoundingMode roundingMode
      Rounding mode used by round function
  • Method Details

    • abs

      public static java.lang.Number abs​(java.lang.Number x) throws ScriptBasicException
      Throws:
      ScriptBasicException
    • acos

      public static double acos​(double x)
    • asin

      public static double asin​(double x)
    • atan

      public static double atan​(double x)
    • atan2

      public static double atan2​(double x, double y)
    • cbrt

      public static double cbrt​(double x)
    • ceil

      public static double ceil​(double x)
    • copySign

      public static double copySign​(double magnitude, double sign)
    • cos

      public static double cos​(double x)
    • cosh

      public static double cosh​(double x)
    • exp

      public static double exp​(double a)
    • expm1

      public static double expm1​(double x)
    • floatF

      public static java.lang.Double floatF​(java.lang.Object s)
      Convert a value to floating point. This method can be called directly from the BASIC program and it will return a java Double, that is internally a BASIC float. (Note that ScriptBasic for Java does not use float or int, only Long and Double.)

      Use this function from the BASIC program if the BASIC interpreter does not convert automatically a number to floating point but you need a floating point number and not an integer.

      Parameters:
      s - the number to convert
      Returns:
      the converted number or null, which means undefined in BASIC in case the parameter s passed can not be converted to floating point
    • integer

      public static java.lang.Long integer​(java.lang.Object s)
      Convert a value to integer. This method can be called directly from the BASIC program and it will return a java Long, that is internally a BASIC integer. (Note that ScriptBasic for Java does not use float or int, only Long and Double.)

      Use this function from the BASIC program if the BASIC interpreter does not convert automatically a number to integer but you need an integer number and not a floating point number.

      Parameters:
      s - the number to convert
      Returns:
      the converted number or null, which means undefined in BASIC in case the parameter s passed can not be converted to integer
    • floor

      public static double floor​(double x)
    • getExponent

      public static java.lang.Long getExponent​(double d)
    • hypot

      public static double hypot​(double x, double y)
    • IEEEremainder

      public static double IEEEremainder​(double f1, double f2)
    • log

      public static double log​(double x)
    • log10

      public static double log10​(double x)
    • log1p

      public static double log1p​(double x)
    • max

      public static java.lang.Number max​(java.lang.Number a, java.lang.Number b)
    • min

      public static java.lang.Number min​(java.lang.Number a, java.lang.Number b)
    • pow

      public static double pow​(double a, double b)
    • random

      public static double random()
    • rint

      public static double rint​(double a)
    • round

      public static java.lang.Number round​(double value, java.lang.Integer numdecimalplaces)
      Returns a number rounded to a specified number of decimal places. This function returns something commonly referred to as bankers rounding. So be careful before using this function. Same behavior has 'round' in VBA.
      Parameters:
      value - Numeric value being rounded
      numdecimalplaces - Number indicating how many places to the right of the decimal are included in the rounding.
      Returns:
      rounded value
    • scalb

      public static double scalb​(double d, int scaleFactor)
    • signum

      public static double signum​(double d)
    • sin

      public static double sin​(double x)
    • sinh

      public static double sinh​(double x)
    • sqrt

      public static double sqrt​(double a)
    • tan

      public static double tan​(double x)
    • tanh

      public static double tanh​(double x)
    • toDegrees

      public static double toDegrees​(double angrad)
    • toRadians

      public static double toRadians​(double angdeg)