remove limits from fact in favour of estimation. Fixes #1065
This commit is contained in:
1 parent
6222c97375
commit
61052ea06d
2 files changed
+15
-3
No files matched your search
@@ -6,11 +6,12 @@ There is bunch of them - they require a number and spit out a number, doing what
|
||||
|
||||
### `fact(n)`
|
||||
|
||||
Factorial of a number, a.k.a `n!`, just not in `scarpet`. Gets big... quick...
|
||||
Factorial of a number, a.k.a `n!`, just not in `scarpet`. Gets big... quick... Therefore, values larger
|
||||
than `fact(20)` will not return the exact value, but a value with 'double-float' precision.
|
||||
|
||||
### `sqrt(n)`
|
||||
|
||||
Square root. For other fancy roots, use `^`, math and yo noggin. Imagine square roots on a tree...
|
||||
Square root (not 'a squirt') of a number. For other fancy roots, use `^`, math and yo noggin. Imagine square roots on a tree...
|
||||
|
||||
### `abs(n)`
|
||||
|
||||
|
||||
@@ -20,12 +20,23 @@ public class Arithmetic {
|
||||
expression.addUnaryFunction("fact", (v) ->
|
||||
{
|
||||
long number = NumericValue.asNumber(v).getLong();
|
||||
long factorial = 1;
|
||||
if (number < 21)
|
||||
{
|
||||
long factorial = 1;
|
||||
for (int i = 1; i <= number; i++)
|
||||
{
|
||||
factorial = factorial * i;
|
||||
}
|
||||
return new NumericValue(factorial);
|
||||
}
|
||||
// values over 21 will exceed long limits
|
||||
double factorial = 1.0;
|
||||
for (int i = 1; i <= number; i++)
|
||||
{
|
||||
factorial = factorial * i;
|
||||
}
|
||||
return new NumericValue(factorial);
|
||||
|
||||
});
|
||||
expression.addMathematicalUnaryFunction("sin", (d) -> Math.sin(Math.toRadians(d)));
|
||||
expression.addMathematicalUnaryFunction("cos", (d) -> Math.cos(Math.toRadians(d)));
|
||||
|
||||
Reference in new issue
Block a user