mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-19 03:51:42 +02:00
Added sqr() and approx()
This commit is contained in:
22
math.scad
22
math.scad
@@ -56,6 +56,18 @@ function quantup(x,y) = ceil(x/y)*y;
|
||||
function constrain(v, minval, maxval) = min(maxval, max(minval, v));
|
||||
|
||||
|
||||
// Function: approx()
|
||||
// Usage:
|
||||
// approx(a,b,[eps])
|
||||
// Description:
|
||||
// Compares two numbers or vectors, and returns true if they are closer than `eps` to each other.
|
||||
// Arguments:
|
||||
// a = First value.
|
||||
// b = Second value.
|
||||
// eps = The maximum allowed difference between `a` and `b` that will return true.
|
||||
function approx(a,b,eps=EPSILON) = let(c=a-b) (is_num(c)? c : norm(c)) <= eps;
|
||||
|
||||
|
||||
// Function: min_index()
|
||||
// Usage:
|
||||
// min_index(vals);
|
||||
@@ -121,6 +133,16 @@ function modrange(x, y, m, step=1) =
|
||||
) [for (i=[a:step:c]) (i%m+m)%m];
|
||||
|
||||
|
||||
// Function: sqr()
|
||||
// Usage:
|
||||
// sqr(x);
|
||||
// Description: Returns the square of the given number.
|
||||
// Examples:
|
||||
// sqr(3); // Returns: 9
|
||||
// sqr(-4); // Returns: 16
|
||||
function sqr(x) = x*x;
|
||||
|
||||
|
||||
// Function: gaussian_rand()
|
||||
// Usage:
|
||||
// gaussian_rand(mean, stddev)
|
||||
|
Reference in New Issue
Block a user