AngelScript

math functions

Path: /sdk/add_on/scriptmath/

This add-on registers the math functions from the standard C runtime library with the script engine. Use `RegisterScriptMath(asIScriptEngine*)` to perform the registration.

By defining the preprocessor word AS_USE_FLOAT=0, the functions will be registered to take and return doubles instead of floats.

The function `RegisterScriptMathComplex(asIScriptEngine*)` registers a type that represents a complex number, i.e. a number with real and imaginary parts.

## Public script interface

      // Trigonometric functions
      float cos(float rad);
      float sin(float rad);
      float tan(float rad);

      // Inverse trigonometric functions
      float acos(float val);
      float asin(float val);
      float atan(float val);
      float atan2(float y, float x);

      // Hyperbolic functions
      float cosh(float rad);
      float sinh(float rad);
      float tanh(float rad);

      // Logarithmic functions
      float log(float val);
      float log10(float val);

      // Power to
      float pow(float val, float exp);

      // Square root
      float sqrt(float val);

      // Absolute value
      float abs(float val);

      // Ceil and floor functions
      float ceil(float val);
      float floor(float val);

      // Returns the fraction
      float fraction(float val);

      // This type represents a complex number with real and imaginary parts
      class complex
      {
        // Constructors
        complex();
        complex(const complex &in);
        complex(float r, float i = 0);

        // Equality operator
        bool opEquals(const complex &in) const;

        // Compound assignment operators
        complex &opAddAssign(const complex &in);
        complex &opSubAssign(const complex &in);
        complex &opMulAssign(const complex &in);
        complex &opDivAssign(const complex &in);

        // Math operators
        complex opAdd(const complex &in) const;
        complex opSub(const complex &in) const;
        complex opMul(const complex &in) const;
        complex opDiv(const complex &in) const;

        // Returns the absolute value (magnitude)
        float abs() const;

        // Swizzle operators
        complex get_ri() const;
        void set_ri(const complex &in);
        complex get_ir() const;
        void set_ir(const complex &in);

        // The real and imaginary parts
        float r;
        float i;
      }