New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Suggestion] Methods to be added #12
Comments
IEEE 754, in subsection 9.2, recommends some additional operations to be predefined:
I think ECMA-262 has all operations that are required in section 5. |
There is a bunch of trigonometric functions used historically that could potentially make some calculations more precise or at least shorter.
|
I suggest |
@OlsonDev Good point, I'll amend the OP. |
These may potentially also be useful // restatement of the above suggestion, in the closed interval [0, 1]
Math.hvs = function (radians) {
return Math.pow(Math.sin(radians / 2), 2);
};
// return value in radians, in the closed interval [0, π]
Math.ahvs = function (haversine) {
return 2 * Math.asin(Math.sqrt(haversine));
};
// haversine of the central angle, in the closed interval [0, 1]
Math.haversineFormula = function (latA, lonA, latB, lonB) {
return Math.hvs(latB - latA) + Math.cos(latA) * Math.cos(latB) * Math.hvs(lonB - lonA);
};
// on the unit sphere, in the closed interval [0, π]
Math.sphericalDistance = function (latA, lonA, latB, lonB) {
return Math.ahvs(Math.haversineFormula(latA, lonA, latB, lonB));
}; |
I also agree that |
//num_list is an arbitrary iterable object here
let d = [...num_list].reduce(Math.gcd, 0) Or this: let d = 0;
for (const x of num_list)
d = Math.gcd(d, x); Can be refactored as this: let d = Math.gcd(...num_list) The output of the empty GCD LCM can be defined as: Math.lcm = function(...args) {
return args.reduce((a, b) => {
a = +a; b = +b;
return a != 0 || b != 0 ? a / Math.gcd(a, b) * b : 0
}, 1)
} Since Now the real problem is non-ints. Should these functions return |
@Crissov I would also recommend this one: Math.sinc = x => +x == 0 ? 1 : Math.sin(x) / x It's important and useful |
Aside from the
randomInteger
from #8 and theMath.sum
from #4, I think that including the methods below would help, especially when languages like Python, Matlab and Processing have them:Math.clamp
Math.log
which would allow the currentMath.log
to be more flexible without breaking it.Math.range
Math.gcd
Math.lcm
Math.factorial
or perhaps a syntactic sugar (like5!
or something not ambiguous)Math.combination
/Math.choose
Math.equivalent
/Math.equiv
/Math.approx
There are other methods I have in mind but the above would be a good start (e.g.
Math.mean
,Math.trimmedAverage
).The text was updated successfully, but these errors were encountered: