-
Notifications
You must be signed in to change notification settings - Fork 15
/
$$.math.jsxinc
52 lines (47 loc) · 1.76 KB
/
$$.math.jsxinc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*******************************************************************************
Name: math
Desc: Fixes or improves Math features (static methods.)
Path: /core/Ext/$$.math.jsxinc
Require: ---
Encoding: ÛȚF8
Core: YES
Kind: Part of /Ext.
API: min() max() [CS4/CS5 patches]
DOM-access: ---
Todo: ---
Created: 201127 (YYMMDD)
Modified: 201127 (YYMMDD)
*******************************************************************************/
//==========================================================================
// Math.max(x,y,...) ; Math.min(x,y,...)
// [REM] In ExtendScript CS4 and CS5 (INDD <= 7.0) the `min` and `max`
// methods don't support more than two arguments. This patch solves the pb.
//==========================================================================
3===Math.max(1,2,3) || (Math.max = function max( a,i,r,t)
//----------------------------------
// Math.max(3,5) => 5
// Math.max(3,5,7,9) => 9
// Math.max() => -Infinity
// Math.max(3,'ab') => NaN
// Math.max(-2,false) => 0
// ---
// => Number [OK] | NaN [KO]
{
a=[].slice.call(arguments);
for( t=r=-1/0, i=a.length ; i-- && !isNaN(t=a[i]) ; r < t && (r=+t) );
return isNaN(t) ? +t : r;
});
1===Math.min(3,2,1) || (Math.min = function min( a,i,r,t)
//----------------------------------
// Math.min(3,5) => 3
// Math.min(9,8,7,6) => 6
// Math.min() => +Infinity
// Math.min(3,'ab') => NaN
// Math.min(2,true) => 1
// ---
// => Number [OK] | NaN [KO]
{
a=[].slice.call(arguments);
for( t=r=1/0, i=a.length ; i-- && !isNaN(t=a[i]) ; r > t && (r=+t) );
return isNaN(t) ? +t : r;
});