Skip to content
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

Math.Factorial doesn't work #7969

Merged
merged 3 commits into from
Jun 27, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ Change Log
* Fixed a bug where image requests that returned HTTP code 204 would prevent any future request from succeeding on browsers that supported ImageBitmap. [#7914](https://github.com/AnalyticalGraphicsInc/cesium/pull/7914/)
* Fixed polyline colors when `scene.highDynamicRange` is enabled. [#7924](https://github.com/AnalyticalGraphicsInc/cesium/pull/7924)
* Fixed a bug in the inspector where the min/max height values of a picked tile were undefined. [#7904](https://github.com/AnalyticalGraphicsInc/cesium/pull/7904)
* Fixed `Math.factorial` to return the correct values. (https://github.com/AnalyticalGraphicsInc/cesium/pull/7969)

### 1.58.1 - 2018-06-03
_This is an npm-only release to fix a publishing issue_.
4 changes: 3 additions & 1 deletion Source/Core/Math.js
Original file line number Diff line number Diff line change
@@ -732,7 +732,9 @@ define([
if (n >= length) {
var sum = factorials[length - 1];
for (var i = length; i <= n; i++) {
factorials.push(sum * i);
var next = sum * i;
factorials.push(next);
sum = next;
}
}
return factorials[n];
22 changes: 20 additions & 2 deletions Specs/Core/MathSpec.js
Original file line number Diff line number Diff line change
@@ -383,8 +383,26 @@ defineSuite([
var factorials = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, 20922789888000, 355687428096000, 6402373705728000,
121645100408832000, 2432902008176640000, 51090942171709440000, 1124000727777607680000, 25852016738884976640000, 620448401733239439360000];

for ( var i = 0; i < factorials.length; i++) {
expect(CesiumMath.factorial(i)).toEqual(factorials[i]);
var length = factorials.length;
var i;
var indices = [];

// Populate indices array
for (i = 0; i < length; i++) {
indices.push(i);
}

// Randomize the indices array
for (i = 0; i < length; i++) {
var tmp = indices[i];
var randomIndex = Math.floor(Math.random() * length);
indices[i] = indices[randomIndex];
indices[randomIndex] = tmp;
}

for (i = 0; i < length; i++) {
var index = indices[i];
expect(CesiumMath.factorial(index)).toEqual(factorials[index]);
}
});