C mathematics for C++ macros. More...
| double | sin(double x) |
| double | cos(double x) |
| double | tan(double x) |
| double | asin(double x) |
| double | acos(double x) |
| double | atan(double x) |
| double | atan2(double y, double x) |
| double | sinh(double x) |
| double | cosh(double x) |
| double | tanh(double x) |
| double | exp(double x) |
| double | log(double x) |
| double | log10(double x) |
| double | pow(double x, double y) |
| double | sqrt(double x) |
| double | hypot(double x, double y) |
| double | floor(double x) |
| double | ceil(double x) |
| double | trunc(double x) |
| double | round(double x) |
| double | fabs(double x) |
| double | fmod(double x, double y) |
| double | fmin(double x, double y) |
| double | fmax(double x, double y) |
| int | isnan(double x) |
| int | isinf(double x) |
| int | isfinite(double x) |
| double | M_E |
| double | M_LOG2E |
| double | M_LOG10E |
| double | M_LN2 |
| double | M_LN10 |
| double | M_PI |
| double | M_PI_2 |
| double | M_PI_4 |
| double | M_SQRT2 |
| double | M_SQRT1_2 |
C mathematics for C++ macros. Load with #include <math.h> or #include <cmath> (same plugin). Available from LayoutEditor 20260918.
This is not the built-in math class. math::sin(x) works without an include. After this include you can also write free sin(x).
Angles are in radians, not degrees. A full circle is 2 * M_PI (about 6.2832). 90° is M_PI / 2. To convert: radians = degrees * M_PI / 180.0.
A double is a floating-point number (can have a decimal point). Integer abs is in stdlib.h. Use fabs here for double.
#include <math.h>
int main(){
double s = sin(M_PI / 2.0); // 1.0
double r = sqrt(4.0); // 2.0
cout("sin(pi/2) = ", s, " sqrt(4) = ", r, "\n");
}
Python: import math (math.sin, math.pi). This include is for C++ macros only.
Sine of an angle. On the unit circle this is the y-coordinate after rotating by x.
Parameters:
x (double) — angle in radians.Returns: double in the range -1 … 1. sin(0) is 0, sin(M_PI / 2) is 1.
Cosine of an angle. On the unit circle this is the x-coordinate after rotating by x.
Parameters:
x (double) — angle in radians.Returns: double in the range -1 … 1. cos(0) is 1, cos(M_PI / 2) is 0.
Tangent of an angle: sin(x) / cos(x). Undefined where cosine is zero (90°, 270°, …).
Parameters:
x (double) — angle in radians.Returns: double. Grows without bound near M_PI / 2.
Inverse sine (arc sine): the angle whose sine is x.
Parameters:
x (double) — must be between -1 and 1 (otherwise the result is not a real number).Returns: double angle in radians, in the range -π/2 … π/2.
Inverse cosine (arc cosine): the angle whose cosine is x.
Parameters:
x (double) — must be between -1 and 1.Returns: double angle in radians, in the range 0 … π.
Inverse tangent of a ratio. It cannot tell the quadrant: atan(1) is 45° whether you are in the first or third quadrant. Prefer atan2 if you have both coordinates.
Parameters:
x (double) — the ratio y/x (or any real number).Returns: double angle in radians, in the range -π/2 … π/2.
Four-quadrant inverse tangent. Give the y and x coordinates of a point; the function returns the angle of that point from the positive x-axis. Unlike atan, it uses the signs of both values, so it knows the quadrant.
Parameters:
y (double) — vertical coordinate (first argument, as in mathematics).x (double) — horizontal coordinate.Returns: double angle in radians, in the range -π … π. atan2(0, 1) is 0; atan2(1, 0) is M_PI / 2.
Hyperbolic sine: (exp(x) - exp(-x)) / 2.
Parameters:
x (double) — real number (not an angle in the usual geometric sense).Returns: double.
Hyperbolic cosine: (exp(x) + exp(-x)) / 2. Always ≥ 1 for real x.
Parameters:
x (double).Returns: double.
Hyperbolic tangent: sinh(x) / cosh(x).
Parameters:
x (double).Returns: double in the range -1 … 1.
Exponential function: e raised to the power x (e ≈ 2.71828, also M_E).
Parameters:
x (double) — the exponent.Returns: double. exp(0) is 1, exp(1) is e.
Natural logarithm (base e). Inverse of exp.
Parameters:
x (double) — must be greater than 0.Returns: double. log(M_E) is 1, log(1) is 0.
Logarithm base 10. Useful for decades (orders of magnitude).
Parameters:
x (double) — must be greater than 0.Returns: double. log10(100) is 2, log10(1e-3) is -3.
Power: x raised to y (xy).
Parameters:
x (double) — base.y (double) — exponent.Returns: double. pow(2, 10) is 1024, pow(9, 0.5) is 3. Negative bases with non-integer exponents can be invalid.
Square root of x.
Parameters:
x (double) — must be ≥ 0.Returns: double ≥ 0. sqrt(0) is 0, sqrt(4) is 2.
Length of the hypotenuse of a right triangle with legs x and y: √(x² + y²). Safer than sqrt(x*x + y*y) for very large values (less overflow).
Parameters:
x (double) — first side.y (double) — second side.Returns: double ≥ 0. hypot(3, 4) is 5.
Largest integer that is not greater than x (rounds toward −∞).
Parameters:
x (double).Returns: double (still a floating type, but the value is whole). floor(2.9) is 2, floor(-2.1) is -3.
Smallest integer that is not smaller than x (rounds toward +∞).
Parameters:
x (double).Returns: double. ceil(2.1) is 3, ceil(-2.9) is -2.
Drops the fractional part (rounds toward 0).
Parameters:
x (double).Returns: double. trunc(2.9) is 2, trunc(-2.9) is -2.
Nearest integer. Halfway cases (2.5, -2.5) follow the C library on your platform (usually away from 0 or to even — do not rely on a specific halfway rule).
Parameters:
x (double).Returns: double. round(2.2) is 2, round(2.8) is 3.
Absolute value of a floating-point number (always ≥ 0).
Parameters:
x (double).Returns: double. fabs(-3.5) is 3.5, fabs(3.5) is 3.5.
Floating-point remainder of x / y: the value r such that x = n*y + r with the same sign as x and |r| < |y|.
Parameters:
x (double) — dividend.y (double) — divisor (must not be 0).Returns: double. fmod(7.5, 2.0) is 1.5.
The smaller of two numbers.
Parameters:
x (double), y (double).Returns: double — whichever is smaller.
The larger of two numbers.
Parameters:
x (double), y (double).Returns: double — whichever is larger.
Tests whether x is NaN (“not a number”, for example 0.0/0.0).
Parameters:
x (double).Returns: non-zero (true) if x is NaN, otherwise 0.
Tests whether x is infinite (+∞ or −∞).
Parameters:
x (double).Returns: non-zero if infinite, otherwise 0.
Tests whether x is a normal finite number (not NaN and not infinite).
Parameters:
x (double).Returns: non-zero if finite, otherwise 0.
Returns: the named constant. e, base of natural logarithms Approximate value: 2.71828.
Returns: the named constant. log₂(e) Approximate value: 1.44270.
Returns: the named constant. log₁₀(e) Approximate value: 0.43429.
Returns: the named constant. ln(2) Approximate value: 0.69315.
Returns: the named constant. ln(10) Approximate value: 2.30259.
Returns: the named constant. π Approximate value: 3.14159.
Returns: the named constant. π/2 Approximate value: 1.57080.
Returns: the named constant. π/4 Approximate value: 0.78540.
Returns: the named constant. √2 Approximate value: 1.41421.
Returns: the named constant. 1/√2 Approximate value: 0.70711.