mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-28 15:59:45 +00:00
Implemented Issue #262
This commit is contained in:
parent
07beb712a2
commit
1435100e37
3 changed files with 9 additions and 8 deletions
12
math.scad
12
math.scad
|
@ -26,17 +26,19 @@ NAN = acos(2); // The value `nan`, useful for comparisons.
|
|||
// Usage:
|
||||
// sqr(x);
|
||||
// Description:
|
||||
// Returns the square of the given number or entries in list
|
||||
// If given a number, returns the square of that number,
|
||||
// If given a vector, returns a vector of the squares of each element in the input vector.
|
||||
// If given a matrix, returns the matrix multiplication of the matrix with itself.
|
||||
// Examples:
|
||||
// sqr(3); // Returns: 9
|
||||
// sqr(-4); // Returns: 16
|
||||
// sqr([3,4]); // Returns: [9,16]
|
||||
// sqr([[1,2],[3,4]]); // Returns [[1,4],[9,16]]
|
||||
// sqr([[1,2],3]); // Returns [[1,4],9]
|
||||
// sqr([[1,2],[3,4]]); // Returns [[7,10],[15,22]]
|
||||
function sqr(x) =
|
||||
is_list(x) ? [for(val=x) sqr(val)] :
|
||||
is_finite(x) ? x*x :
|
||||
assert(is_finite(x) || is_vector(x), "Input is not a number nor a list of numbers.");
|
||||
is_vector(x) ? vmul(x,x) :
|
||||
is_matrix(x) ? x*x :
|
||||
assert(is_finite(x) || is_vector(x) || is_matrix(x), "Input is not a number nor a list of numbers.");
|
||||
|
||||
|
||||
// Function: log2()
|
||||
|
|
|
@ -314,8 +314,7 @@ module test_sqr() {
|
|||
assert_equal(sqr(3), 9);
|
||||
assert_equal(sqr(16), 256);
|
||||
assert_equal(sqr([2,3,4]), [4,9,16]);
|
||||
assert_equal(sqr([[2,3,4],[3,5,7]]), [[4,9,16],[9,25,49]]);
|
||||
assert_equal(sqr([]),[]);
|
||||
assert_equal(sqr([[2,3,4],[3,5,7],[3,5,1]]), [[25,41,33],[42,69,54],[24,39,48]]);
|
||||
}
|
||||
test_sqr();
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
BOSL_VERSION = [2,0,430];
|
||||
BOSL_VERSION = [2,0,431];
|
||||
|
||||
|
||||
// Section: BOSL Library Version Functions
|
||||
|
|
Loading…
Reference in a new issue