Added sqrt to Scalar and Vector
This commit is contained in:
+13
-2
@@ -68,7 +68,6 @@ pub fn add(comptime a: Self, comptime b: Self) Self {
|
||||
|
||||
/// Subtract exponents component-wise. Used internally by `divBy`.
|
||||
pub fn sub(comptime a: Self, comptime b: Self) Self {
|
||||
@setEvalBranchQuota(10_000);
|
||||
var result = Self.initFill(0);
|
||||
inline for (std.enums.values(Dimension)) |d|
|
||||
result.set(d, a.get(d) - b.get(d));
|
||||
@@ -77,13 +76,19 @@ pub fn sub(comptime a: Self, comptime b: Self) Self {
|
||||
|
||||
/// Multiply exponents by a scalar integer. Used internally by `pow` in Scalar.
|
||||
pub fn scale(comptime a: Self, comptime exp: comptime_int) Self {
|
||||
@setEvalBranchQuota(10_000);
|
||||
var result = Self.initFill(0);
|
||||
inline for (std.enums.values(Dimension)) |d|
|
||||
result.set(d, a.get(d) * exp);
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn div(comptime a: Self, comptime exp: comptime_int) Self {
|
||||
var result = Self.initFill(0);
|
||||
inline for (std.enums.values(Dimension)) |d|
|
||||
result.set(d, a.get(d) / exp);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Returns true if every dimension exponent is equal. Used to enforce type compatibility in `add`, `sub`, `to`.
|
||||
pub fn eql(comptime a: Self, comptime b: Self) bool {
|
||||
inline for (std.enums.values(Dimension)) |d|
|
||||
@@ -91,6 +96,12 @@ pub fn eql(comptime a: Self, comptime b: Self) bool {
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn isSquare(comptime a: Self) bool {
|
||||
inline for (std.enums.values(Dimension)) |d|
|
||||
if (a.get(d) % 2 != 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn str(comptime a: Self) []const u8 {
|
||||
var out: []const u8 = "";
|
||||
const dims = std.enums.values(Dimension);
|
||||
|
||||
Reference in New Issue
Block a user