Skip to content

Commit eefaa42

Browse files
author
Omar Shehata
authored
Merge pull request #7969 from AnalyticalGraphicsInc/factorial
Math.Factorial doesn't work
2 parents a370868 + 2ea4442 commit eefaa42

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Change Log
1515
* 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/)
1616
* Fixed polyline colors when `scene.highDynamicRange` is enabled. [#7924](https://github.com/AnalyticalGraphicsInc/cesium/pull/7924)
1717
* 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)
18+
* Fixed `Math.factorial` to return the correct values. (https://github.com/AnalyticalGraphicsInc/cesium/pull/7969)
1819

1920
### 1.58.1 - 2018-06-03
2021
_This is an npm-only release to fix a publishing issue_.

Source/Core/Math.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,9 @@ define([
732732
if (n >= length) {
733733
var sum = factorials[length - 1];
734734
for (var i = length; i <= n; i++) {
735-
factorials.push(sum * i);
735+
var next = sum * i;
736+
factorials.push(next);
737+
sum = next;
736738
}
737739
}
738740
return factorials[n];

Specs/Core/MathSpec.js

+20-2
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,26 @@ defineSuite([
383383
var factorials = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, 20922789888000, 355687428096000, 6402373705728000,
384384
121645100408832000, 2432902008176640000, 51090942171709440000, 1124000727777607680000, 25852016738884976640000, 620448401733239439360000];
385385

386-
for ( var i = 0; i < factorials.length; i++) {
387-
expect(CesiumMath.factorial(i)).toEqual(factorials[i]);
386+
var length = factorials.length;
387+
var i;
388+
var indices = [];
389+
390+
// Populate indices array
391+
for (i = 0; i < length; i++) {
392+
indices.push(i);
393+
}
394+
395+
// Randomize the indices array
396+
for (i = 0; i < length; i++) {
397+
var tmp = indices[i];
398+
var randomIndex = Math.floor(Math.random() * length);
399+
indices[i] = indices[randomIndex];
400+
indices[randomIndex] = tmp;
401+
}
402+
403+
for (i = 0; i < length; i++) {
404+
var index = indices[i];
405+
expect(CesiumMath.factorial(index)).toEqual(factorials[index]);
388406
}
389407
});
390408

0 commit comments

Comments
 (0)