Merge lp:~rpadovani/ubuntu-calculator-app/1332567 into lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk
- 1332567
- Merge into old_trunk
Status: | Merged |
---|---|
Approved by: | Alan Pope πΊπ§π± π¦ |
Approved revision: | 286 |
Merged at revision: | 288 |
Proposed branch: | lp:~rpadovani/ubuntu-calculator-app/1332567 |
Merge into: | lp:~ubuntu-calculator-dev/ubuntu-calculator-app/old_trunk |
Diff against target: |
1246 lines (+189/-171) 1 file modified
bignumber.js (+189/-171) |
To merge this branch: | bzr merge lp:~rpadovani/ubuntu-calculator-app/1332567 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot | continuous-integration | Approve | |
Renato Araujo Oliveira Filho (community) | Approve | ||
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Bartosz Kosiorek | Needs Information | ||
Victor Thompson (community) | Approve | ||
Mihir Soni | Approve | ||
Alan Pope πΊπ§π± π¦ | Pending | ||
Review via email: mp+225225@code.launchpad.net |
Commit message
Updated bignumber.js, added a workaround for bug #1332567
Description of the change
Due bug #1332567 when device is connected to charger it does wrong divisions.
I'm pretty sure I have identified the origin of the bug: in bignumber.js there is function named "division", which has a do/while cycle inside.
Before the do/while cycle all vars are equal on desktop and on device, but after the cycle the array named qc is different.
So, I started to debug the do/while cycle, but everytime I add a console.log() in the do/while cycle, the bug disappears. I think is an Heisenbug[1].
I suppose the bug is in the QT 5.3 Javascript Interpreter, and I'm working to reproduce the bug with a simplier code.
Until the fix of the bug in the interpreter, I suggest to add a console.log() in the do/while cycle as a workaround.
Also, I updated the library to latest version
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
Bartosz Kosiorek (gang65) wrote : | # |
Looks ok. Great job!
Mihir Soni (mihirsoni) wrote : | # |
Change looks good to me , it works great on desktop with new upgraded version of js file.
But still haven't tested on device.
Bartosz Kosiorek (gang65) wrote : | # |
Could you please submit bug report for QT 5.3 Javascript Interpreter?
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
http://
Executed test runs:
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
- 285. By Riccardo Padovani
- 286. By Riccardo Padovani
-
Removed old workaround
Riccardo Padovani (rpadovani) wrote : | # |
I merged Victor fix that is better. Seems that in specific occasions the QT interpreter is too slow. I'll talk with someone in the sdk team and I'll report the bug upstream
Bartosz Kosiorek (gang65) wrote : | # |
Great work.
One more comment.
Could you please extend autopilot test case, to handle this divine problem in future?
You could change for example from:
def test_divide_
To:
def test_divide_
Maybe it will be good to submit this bignumber fix to upstream:
https:/
Bartosz Kosiorek (gang65) wrote : | # |
Or maybe better 4.5/2 = 2.25
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:286
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Riccardo Padovani (rpadovani) wrote : | # |
> Could you please extend autopilot test case, to handle this divine problem in future?
We have a testcase about this, is 1/3. It's thanks to this test case we found
the bug
> Maybe it will be good to submit this bignumber fix to upstream:
> https:/
I reported the bug upstream and linked Victor's patch. I know it's trivial
change, but I prefer to know author's opinion before do a MR :-)
Renato Araujo Oliveira Filho (renatofilho) wrote : | # |
works for me.
PS Jenkins bot (ps-jenkins) : | # |
Preview Diff
1 | === modified file 'bignumber.js' | |||
2 | --- bignumber.js 2014-04-26 17:59:39 +0000 | |||
3 | +++ bignumber.js 2014-07-02 14:22:11 +0000 | |||
4 | @@ -1,12 +1,19 @@ | |||
6 | 1 | /* bignumber.js v1.3.0 https://github.com/MikeMcl/bignumber.js/LICENCE */ | 1 | /*! bignumber.js v1.4.1 https://github.com/MikeMcl/bignumber.js/LICENCE */ |
7 | 2 | 2 | ||
8 | 3 | var BN; | 3 | var BN; |
9 | 4 | 4 | ||
10 | 5 | /* Due bug https://bugs.launchpad.net/ubuntu-calculator-app/+bug/1332567 | ||
11 | 6 | * there is a change after line 598, remember to add it when you update | ||
12 | 7 | * the file | ||
13 | 8 | * See | ||
14 | 9 | * https://code.launchpad.net/~vthompson/ubuntu-calculator-app/test-fix-1332567 | ||
15 | 10 | */ | ||
16 | 11 | |||
17 | 5 | ;(function ( global ) { | 12 | ;(function ( global ) { |
18 | 6 | 'use strict'; | 13 | 'use strict'; |
19 | 7 | 14 | ||
20 | 8 | /* | 15 | /* |
22 | 9 | bignumber.js v1.3.0 | 16 | bignumber.js v1.4.1 |
23 | 10 | A JavaScript library for arbitrary-precision arithmetic. | 17 | A JavaScript library for arbitrary-precision arithmetic. |
24 | 11 | https://github.com/MikeMcl/bignumber.js | 18 | https://github.com/MikeMcl/bignumber.js |
25 | 12 | Copyright (c) 2012 Michael Mclaughlin <M8ch88l@gmail.com> | 19 | Copyright (c) 2012 Michael Mclaughlin <M8ch88l@gmail.com> |
26 | @@ -114,7 +121,7 @@ | |||
27 | 114 | x['s'] = n['s']; | 121 | x['s'] = n['s']; |
28 | 115 | x['e'] = n['e']; | 122 | x['e'] = n['e']; |
29 | 116 | x['c'] = ( n = n['c'] ) ? n.slice() : n; | 123 | x['c'] = ( n = n['c'] ) ? n.slice() : n; |
31 | 117 | return | 124 | return; |
32 | 118 | } | 125 | } |
33 | 119 | } | 126 | } |
34 | 120 | 127 | ||
35 | @@ -122,7 +129,7 @@ | |||
36 | 122 | if ( typeof n != 'string' ) { | 129 | if ( typeof n != 'string' ) { |
37 | 123 | n = ( isNum = typeof n == 'number' || | 130 | n = ( isNum = typeof n == 'number' || |
38 | 124 | Object.prototype.toString.call(n) == '[object Number]' ) && | 131 | Object.prototype.toString.call(n) == '[object Number]' ) && |
40 | 125 | n === 0 && 1 / n < 0 ? '-0' : n + '' | 132 | n === 0 && 1 / n < 0 ? '-0' : n + ''; |
41 | 126 | } | 133 | } |
42 | 127 | 134 | ||
43 | 128 | orig = n; | 135 | orig = n; |
44 | @@ -130,7 +137,7 @@ | |||
45 | 130 | if ( b === e && isValid.test(n) ) { | 137 | if ( b === e && isValid.test(n) ) { |
46 | 131 | 138 | ||
47 | 132 | // Determine sign. | 139 | // Determine sign. |
49 | 133 | x['s'] = n.charAt(0) == '-' ? ( n = n.slice(1), -1 ) : 1 | 140 | x['s'] = n.charAt(0) == '-' ? ( n = n.slice(1), -1 ) : 1; |
50 | 134 | 141 | ||
51 | 135 | // Either n is not a valid BigNumber or a base has been specified. | 142 | // Either n is not a valid BigNumber or a base has been specified. |
52 | 136 | } else { | 143 | } else { |
53 | @@ -139,7 +146,7 @@ | |||
54 | 139 | // Ensure return value is rounded to DECIMAL_PLACES as with other bases. | 146 | // Ensure return value is rounded to DECIMAL_PLACES as with other bases. |
55 | 140 | if ( b == 10 ) { | 147 | if ( b == 10 ) { |
56 | 141 | 148 | ||
58 | 142 | return setMode( n, DECIMAL_PLACES, ROUNDING_MODE ) | 149 | return setMode( n, DECIMAL_PLACES, ROUNDING_MODE ); |
59 | 143 | } | 150 | } |
60 | 144 | 151 | ||
61 | 145 | n = trim.call(n).replace( /^\+(?!-)/, '' ); | 152 | n = trim.call(n).replace( /^\+(?!-)/, '' ); |
62 | @@ -163,22 +170,22 @@ | |||
63 | 163 | 170 | ||
64 | 164 | if ( isNum ) { | 171 | if ( isNum ) { |
65 | 165 | 172 | ||
67 | 166 | if ( n.replace( /^0\.0*|\./, '' ).length > 11 ) { | 173 | if ( n.replace( /^0\.0*|\./, '' ).length > 15 ) { |
68 | 167 | 174 | ||
71 | 168 | // 'new BigNumber() number type has more than 11 significant digits: {n}' | 175 | // 'new BigNumber() number type has more than 15 significant digits: {n}' |
72 | 169 | ifExceptionsThrow( orig, 0 ) | 176 | ifExceptionsThrow( orig, 0 ); |
73 | 170 | } | 177 | } |
74 | 171 | 178 | ||
75 | 172 | // Prevent later check for length on converted number. | 179 | // Prevent later check for length on converted number. |
77 | 173 | isNum = !isNum | 180 | isNum = !isNum; |
78 | 174 | } | 181 | } |
80 | 175 | n = convert( n, 10, b, x['s'] ) | 182 | n = convert( n, 10, b, x['s'] ); |
81 | 176 | 183 | ||
82 | 177 | } else if ( n != 'Infinity' && n != 'NaN' ) { | 184 | } else if ( n != 'Infinity' && n != 'NaN' ) { |
83 | 178 | 185 | ||
84 | 179 | // 'new BigNumber() not a base {b} number: {n}' | 186 | // 'new BigNumber() not a base {b} number: {n}' |
85 | 180 | ifExceptionsThrow( orig, 1, b ); | 187 | ifExceptionsThrow( orig, 1, b ); |
87 | 181 | n = 'NaN' | 188 | n = 'NaN'; |
88 | 182 | } | 189 | } |
89 | 183 | } else { | 190 | } else { |
90 | 184 | 191 | ||
91 | @@ -187,10 +194,10 @@ | |||
92 | 187 | ifExceptionsThrow( b, 2 ); | 194 | ifExceptionsThrow( b, 2 ); |
93 | 188 | 195 | ||
94 | 189 | // Ignore base. | 196 | // Ignore base. |
96 | 190 | valid = isValid.test(n) | 197 | valid = isValid.test(n); |
97 | 191 | } | 198 | } |
98 | 192 | } else { | 199 | } else { |
100 | 193 | valid = isValid.test(n) | 200 | valid = isValid.test(n); |
101 | 194 | } | 201 | } |
102 | 195 | 202 | ||
103 | 196 | if ( !valid ) { | 203 | if ( !valid ) { |
104 | @@ -205,19 +212,19 @@ | |||
105 | 205 | if ( n != 'NaN' ) { | 212 | if ( n != 'NaN' ) { |
106 | 206 | 213 | ||
107 | 207 | // 'new BigNumber() not a number: {n}' | 214 | // 'new BigNumber() not a number: {n}' |
109 | 208 | ifExceptionsThrow( orig, 3 ) | 215 | ifExceptionsThrow( orig, 3 ); |
110 | 209 | } | 216 | } |
112 | 210 | x['s'] = null | 217 | x['s'] = null; |
113 | 211 | } | 218 | } |
114 | 212 | id = 0; | 219 | id = 0; |
115 | 213 | 220 | ||
117 | 214 | return | 221 | return; |
118 | 215 | } | 222 | } |
119 | 216 | } | 223 | } |
120 | 217 | 224 | ||
121 | 218 | // Decimal point? | 225 | // Decimal point? |
122 | 219 | if ( ( e = n.indexOf('.') ) > -1 ) { | 226 | if ( ( e = n.indexOf('.') ) > -1 ) { |
124 | 220 | n = n.replace( '.', '' ) | 227 | n = n.replace( '.', '' ); |
125 | 221 | } | 228 | } |
126 | 222 | 229 | ||
127 | 223 | // Exponential form? | 230 | // Exponential form? |
128 | @@ -225,15 +232,15 @@ | |||
129 | 225 | 232 | ||
130 | 226 | // Determine exponent. | 233 | // Determine exponent. |
131 | 227 | if ( e < 0 ) { | 234 | if ( e < 0 ) { |
133 | 228 | e = i | 235 | e = i; |
134 | 229 | } | 236 | } |
135 | 230 | e += +n.slice( i + 1 ); | 237 | e += +n.slice( i + 1 ); |
137 | 231 | n = n.substring( 0, i ) | 238 | n = n.substring( 0, i ); |
138 | 232 | 239 | ||
139 | 233 | } else if ( e < 0 ) { | 240 | } else if ( e < 0 ) { |
140 | 234 | 241 | ||
141 | 235 | // Integer. | 242 | // Integer. |
143 | 236 | e = n.length | 243 | e = n.length; |
144 | 237 | } | 244 | } |
145 | 238 | 245 | ||
146 | 239 | // Determine leading zeros. | 246 | // Determine leading zeros. |
147 | @@ -242,11 +249,11 @@ | |||
148 | 242 | 249 | ||
149 | 243 | b = n.length; | 250 | b = n.length; |
150 | 244 | 251 | ||
153 | 245 | // Disallow numbers with over 11 significant digits if number type. | 252 | // Disallow numbers with over 15 significant digits if number type. |
154 | 246 | if ( isNum && b > 11 && n.slice(i).length > 11 ) { | 253 | if ( isNum && b > 15 && n.slice(i).length > 15 ) { |
155 | 247 | 254 | ||
158 | 248 | // 'new BigNumber() number type has more than 11 significant digits: {n}' | 255 | // 'new BigNumber() number type has more than 15 significant digits: {n}' |
159 | 249 | ifExceptionsThrow( orig, 0 ) | 256 | ifExceptionsThrow( orig, 0 ); |
160 | 250 | } | 257 | } |
161 | 251 | id = 0; | 258 | id = 0; |
162 | 252 | 259 | ||
163 | @@ -254,13 +261,13 @@ | |||
164 | 254 | if ( ( e -= i + 1 ) > MAX_EXP ) { | 261 | if ( ( e -= i + 1 ) > MAX_EXP ) { |
165 | 255 | 262 | ||
166 | 256 | // Infinity. | 263 | // Infinity. |
168 | 257 | x['c'] = x['e'] = null | 264 | x['c'] = x['e'] = null; |
169 | 258 | 265 | ||
170 | 259 | // Zero or underflow? | 266 | // Zero or underflow? |
171 | 260 | } else if ( i == b || e < MIN_EXP ) { | 267 | } else if ( i == b || e < MIN_EXP ) { |
172 | 261 | 268 | ||
173 | 262 | // Zero. | 269 | // Zero. |
175 | 263 | x['c'] = [ x['e'] = 0 ] | 270 | x['c'] = [ x['e'] = 0 ]; |
176 | 264 | } else { | 271 | } else { |
177 | 265 | 272 | ||
178 | 266 | // Determine trailing zeros. | 273 | // Determine trailing zeros. |
179 | @@ -314,7 +321,7 @@ | |||
180 | 314 | c = 'config', | 321 | c = 'config', |
181 | 315 | inRange = function ( n, lo, hi ) { | 322 | inRange = function ( n, lo, hi ) { |
182 | 316 | return !( ( outOfRange = n < lo || n > hi ) || | 323 | return !( ( outOfRange = n < lo || n > hi ) || |
184 | 317 | parse(n) != n && n !== 0 ) | 324 | parse(n) != n && n !== 0 ); |
185 | 318 | }, | 325 | }, |
186 | 319 | has = o && typeof o == 'object' | 326 | has = o && typeof o == 'object' |
187 | 320 | ? function () {if ( o.hasOwnProperty(p) ) return ( v = o[p] ) != null} | 327 | ? function () {if ( o.hasOwnProperty(p) ) return ( v = o[p] ) != null} |
188 | @@ -324,12 +331,12 @@ | |||
189 | 324 | if ( has( p = 'DECIMAL_PLACES' ) ) { | 331 | if ( has( p = 'DECIMAL_PLACES' ) ) { |
190 | 325 | 332 | ||
191 | 326 | if ( inRange( v, 0, MAX ) ) { | 333 | if ( inRange( v, 0, MAX ) ) { |
193 | 327 | DECIMAL_PLACES = v | 0 | 334 | DECIMAL_PLACES = v | 0; |
194 | 328 | } else { | 335 | } else { |
195 | 329 | 336 | ||
196 | 330 | // 'config() DECIMAL_PLACES not an integer: {v}' | 337 | // 'config() DECIMAL_PLACES not an integer: {v}' |
197 | 331 | // 'config() DECIMAL_PLACES out of range: {v}' | 338 | // 'config() DECIMAL_PLACES out of range: {v}' |
199 | 332 | ifExceptionsThrow( v, p, c ) | 339 | ifExceptionsThrow( v, p, c ); |
200 | 333 | } | 340 | } |
201 | 334 | } | 341 | } |
202 | 335 | r[p] = DECIMAL_PLACES; | 342 | r[p] = DECIMAL_PLACES; |
203 | @@ -338,12 +345,12 @@ | |||
204 | 338 | if ( has( p = 'ROUNDING_MODE' ) ) { | 345 | if ( has( p = 'ROUNDING_MODE' ) ) { |
205 | 339 | 346 | ||
206 | 340 | if ( inRange( v, 0, 8 ) ) { | 347 | if ( inRange( v, 0, 8 ) ) { |
208 | 341 | ROUNDING_MODE = v | 0 | 348 | ROUNDING_MODE = v | 0; |
209 | 342 | } else { | 349 | } else { |
210 | 343 | 350 | ||
211 | 344 | // 'config() ROUNDING_MODE not an integer: {v}' | 351 | // 'config() ROUNDING_MODE not an integer: {v}' |
212 | 345 | // 'config() ROUNDING_MODE out of range: {v}' | 352 | // 'config() ROUNDING_MODE out of range: {v}' |
214 | 346 | ifExceptionsThrow( v, p, c ) | 353 | ifExceptionsThrow( v, p, c ); |
215 | 347 | } | 354 | } |
216 | 348 | } | 355 | } |
217 | 349 | r[p] = ROUNDING_MODE; | 356 | r[p] = ROUNDING_MODE; |
218 | @@ -355,15 +362,16 @@ | |||
219 | 355 | if ( has( p = 'EXPONENTIAL_AT' ) ) { | 362 | if ( has( p = 'EXPONENTIAL_AT' ) ) { |
220 | 356 | 363 | ||
221 | 357 | if ( inRange( v, -MAX, MAX ) ) { | 364 | if ( inRange( v, -MAX, MAX ) ) { |
223 | 358 | TO_EXP_NEG = -( TO_EXP_POS = ~~( v < 0 ? -v : +v ) ) | 365 | TO_EXP_NEG = -( TO_EXP_POS = ~~( v < 0 ? -v : +v ) ); |
224 | 359 | } else if ( !outOfRange && v && inRange( v[0], -MAX, 0 ) && | 366 | } else if ( !outOfRange && v && inRange( v[0], -MAX, 0 ) && |
225 | 360 | inRange( v[1], 0, MAX ) ) { | 367 | inRange( v[1], 0, MAX ) ) { |
227 | 361 | TO_EXP_NEG = ~~v[0], TO_EXP_POS = ~~v[1] | 368 | TO_EXP_NEG = ~~v[0]; |
228 | 369 | TO_EXP_POS = ~~v[1]; | ||
229 | 362 | } else { | 370 | } else { |
230 | 363 | 371 | ||
231 | 364 | // 'config() EXPONENTIAL_AT not an integer or not [integer, integer]: {v}' | 372 | // 'config() EXPONENTIAL_AT not an integer or not [integer, integer]: {v}' |
232 | 365 | // 'config() EXPONENTIAL_AT out of range or not [negative, positive: {v}' | 373 | // 'config() EXPONENTIAL_AT out of range or not [negative, positive: {v}' |
234 | 366 | ifExceptionsThrow( v, p, c, 1 ) | 374 | ifExceptionsThrow( v, p, c, 1 ); |
235 | 367 | } | 375 | } |
236 | 368 | } | 376 | } |
237 | 369 | r[p] = [ TO_EXP_NEG, TO_EXP_POS ]; | 377 | r[p] = [ TO_EXP_NEG, TO_EXP_POS ]; |
238 | @@ -375,15 +383,15 @@ | |||
239 | 375 | if ( has( p = 'RANGE' ) ) { | 383 | if ( has( p = 'RANGE' ) ) { |
240 | 376 | 384 | ||
241 | 377 | if ( inRange( v, -MAX, MAX ) && ~~v ) { | 385 | if ( inRange( v, -MAX, MAX ) && ~~v ) { |
243 | 378 | MIN_EXP = -( MAX_EXP = ~~( v < 0 ? -v : +v ) ) | 386 | MIN_EXP = -( MAX_EXP = ~~( v < 0 ? -v : +v ) ); |
244 | 379 | } else if ( !outOfRange && v && inRange( v[0], -MAX, -1 ) && | 387 | } else if ( !outOfRange && v && inRange( v[0], -MAX, -1 ) && |
245 | 380 | inRange( v[1], 1, MAX ) ) { | 388 | inRange( v[1], 1, MAX ) ) { |
247 | 381 | MIN_EXP = ~~v[0], MAX_EXP = ~~v[1] | 389 | MIN_EXP = ~~v[0], MAX_EXP = ~~v[1]; |
248 | 382 | } else { | 390 | } else { |
249 | 383 | 391 | ||
250 | 384 | // 'config() RANGE not a non-zero integer or not [integer, integer]: {v}' | 392 | // 'config() RANGE not a non-zero integer or not [integer, integer]: {v}' |
251 | 385 | // 'config() RANGE out of range or not [negative, positive: {v}' | 393 | // 'config() RANGE out of range or not [negative, positive: {v}' |
253 | 386 | ifExceptionsThrow( v, p, c, 1, 1 ) | 394 | ifExceptionsThrow( v, p, c, 1, 1 ); |
254 | 387 | } | 395 | } |
255 | 388 | } | 396 | } |
256 | 389 | r[p] = [ MIN_EXP, MAX_EXP ]; | 397 | r[p] = [ MIN_EXP, MAX_EXP ]; |
257 | @@ -394,16 +402,16 @@ | |||
258 | 394 | if ( v === !!v || v === 1 || v === 0 ) { | 402 | if ( v === !!v || v === 1 || v === 0 ) { |
259 | 395 | parse = ( outOfRange = id = 0, ERRORS = !!v ) | 403 | parse = ( outOfRange = id = 0, ERRORS = !!v ) |
260 | 396 | ? parseInt | 404 | ? parseInt |
262 | 397 | : parseFloat | 405 | : parseFloat; |
263 | 398 | } else { | 406 | } else { |
264 | 399 | 407 | ||
265 | 400 | // 'config() ERRORS not a boolean or binary digit: {v}' | 408 | // 'config() ERRORS not a boolean or binary digit: {v}' |
267 | 401 | ifExceptionsThrow( v, p, c, 0, 0, 1 ) | 409 | ifExceptionsThrow( v, p, c, 0, 0, 1 ); |
268 | 402 | } | 410 | } |
269 | 403 | } | 411 | } |
270 | 404 | r[p] = ERRORS; | 412 | r[p] = ERRORS; |
271 | 405 | 413 | ||
273 | 406 | return r | 414 | return r; |
274 | 407 | }; | 415 | }; |
275 | 408 | 416 | ||
276 | 409 | 417 | ||
277 | @@ -422,7 +430,7 @@ | |||
278 | 422 | ( isRange ? ' non-zero' : 'n' ) + ' integer'; | 430 | ( isRange ? ' non-zero' : 'n' ) + ' integer'; |
279 | 423 | 431 | ||
280 | 424 | message = ( [ | 432 | message = ( [ |
282 | 425 | method + ' number type has more than 11 significant digits', | 433 | method + ' number type has more than 15 significant digits', |
283 | 426 | method + ' not a base ' + j + ' number', | 434 | method + ' not a base ' + j + ' number', |
284 | 427 | method + ' base' + message, | 435 | method + ' base' + message, |
285 | 428 | method + ' not a number' ][i] || | 436 | method + ' not a number' ][i] || |
286 | @@ -438,7 +446,7 @@ | |||
287 | 438 | error = new Error(message); | 446 | error = new Error(message); |
288 | 439 | error['name'] = 'BigNumber Error'; | 447 | error['name'] = 'BigNumber Error'; |
289 | 440 | 448 | ||
291 | 441 | throw error | 449 | throw error; |
292 | 442 | } | 450 | } |
293 | 443 | } | 451 | } |
294 | 444 | 452 | ||
295 | @@ -471,15 +479,15 @@ | |||
296 | 471 | if ( arr[j] > baseOut - 1 ) { | 479 | if ( arr[j] > baseOut - 1 ) { |
297 | 472 | 480 | ||
298 | 473 | if ( arr[j + 1] == null ) { | 481 | if ( arr[j + 1] == null ) { |
300 | 474 | arr[j + 1] = 0 | 482 | arr[j + 1] = 0; |
301 | 475 | } | 483 | } |
302 | 476 | arr[j + 1] += arr[j] / baseOut ^ 0; | 484 | arr[j + 1] += arr[j] / baseOut ^ 0; |
304 | 477 | arr[j] %= baseOut | 485 | arr[j] %= baseOut; |
305 | 478 | } | 486 | } |
306 | 479 | } | 487 | } |
307 | 480 | } | 488 | } |
308 | 481 | 489 | ||
310 | 482 | return arr.reverse() | 490 | return arr.reverse(); |
311 | 483 | } | 491 | } |
312 | 484 | 492 | ||
313 | 485 | // Convert array to string. | 493 | // Convert array to string. |
314 | @@ -492,11 +500,11 @@ | |||
315 | 492 | for ( ; i < arrL; str += DIGITS.charAt( arr[i++] ) ) { | 500 | for ( ; i < arrL; str += DIGITS.charAt( arr[i++] ) ) { |
316 | 493 | } | 501 | } |
317 | 494 | 502 | ||
319 | 495 | return str | 503 | return str; |
320 | 496 | } | 504 | } |
321 | 497 | 505 | ||
322 | 498 | if ( baseIn < 37 ) { | 506 | if ( baseIn < 37 ) { |
324 | 499 | nStr = nStr.toLowerCase() | 507 | nStr = nStr.toLowerCase(); |
325 | 500 | } | 508 | } |
326 | 501 | 509 | ||
327 | 502 | /* | 510 | /* |
328 | @@ -539,7 +547,7 @@ | |||
329 | 539 | } | 547 | } |
330 | 540 | 548 | ||
331 | 541 | // Append the fraction part to the converted integer part. | 549 | // Append the fraction part to the converted integer part. |
333 | 542 | nStr = arrToStr(nArr) + '.' + arrToStr(fracArr) | 550 | nStr = arrToStr(nArr) + '.' + arrToStr(fracArr); |
334 | 543 | 551 | ||
335 | 544 | // fracArr is [1]. | 552 | // fracArr is [1]. |
336 | 545 | // Fraction digits rounded up, so increment last digit of integer part. | 553 | // Fraction digits rounded up, so increment last digit of integer part. |
337 | @@ -547,23 +555,23 @@ | |||
338 | 547 | 555 | ||
339 | 548 | if ( nArr[ e = nArr.length - 1 ] < baseOut - 1 ) { | 556 | if ( nArr[ e = nArr.length - 1 ] < baseOut - 1 ) { |
340 | 549 | ++nArr[e]; | 557 | ++nArr[e]; |
342 | 550 | nStr = arrToStr(nArr) | 558 | nStr = arrToStr(nArr); |
343 | 551 | } else { | 559 | } else { |
344 | 552 | nStr = new BigNumber( arrToStr(nArr), | 560 | nStr = new BigNumber( arrToStr(nArr), |
346 | 553 | baseOut )['plus'](ONE)['toS'](baseOut) | 561 | baseOut )['plus'](ONE)['toS'](baseOut); |
347 | 554 | } | 562 | } |
348 | 555 | 563 | ||
349 | 556 | // fracArr is [0]. No fraction digits. | 564 | // fracArr is [0]. No fraction digits. |
350 | 557 | } else { | 565 | } else { |
352 | 558 | nStr = arrToStr(nArr) | 566 | nStr = arrToStr(nArr); |
353 | 559 | } | 567 | } |
354 | 560 | } else { | 568 | } else { |
355 | 561 | 569 | ||
356 | 562 | // Simple integer. Convert base. | 570 | // Simple integer. Convert base. |
358 | 563 | nStr = arrToStr( strToArr(nStr) ) | 571 | nStr = arrToStr( strToArr(nStr) ); |
359 | 564 | } | 572 | } |
360 | 565 | 573 | ||
362 | 566 | return nStr | 574 | return nStr; |
363 | 567 | } | 575 | } |
364 | 568 | 576 | ||
365 | 569 | 577 | ||
366 | @@ -591,19 +599,18 @@ | |||
367 | 591 | dvsZ.unshift(0); | 599 | dvsZ.unshift(0); |
368 | 592 | 600 | ||
369 | 593 | do { | 601 | do { |
370 | 594 | |||
371 | 595 | // 'next' is how many times the divisor goes into the current remainder. | 602 | // 'next' is how many times the divisor goes into the current remainder. |
372 | 596 | for ( next = 0; next < base; next++ ) { | 603 | for ( next = 0; next < base; next++ ) { |
373 | 597 | 604 | ||
374 | 598 | // Compare divisor and remainder. | 605 | // Compare divisor and remainder. |
375 | 599 | if ( dvsL != ( remL = rem.length ) ) { | 606 | if ( dvsL != ( remL = rem.length ) ) { |
377 | 600 | cmp = dvsL > remL ? 1 : -1 | 607 | cmp = dvsL > remL ? 1 : -1; |
378 | 601 | } else { | 608 | } else { |
379 | 602 | for ( remI = -1, cmp = 0; ++remI < dvsL; ) { | 609 | for ( remI = -1, cmp = 0; ++remI < dvsL; ) { |
380 | 603 | 610 | ||
381 | 604 | if ( dvs[remI] != rem[remI] ) { | 611 | if ( dvs[remI] != rem[remI] ) { |
382 | 605 | cmp = dvs[remI] > rem[remI] ? 1 : -1; | 612 | cmp = dvs[remI] > rem[remI] ? 1 : -1; |
384 | 606 | break | 613 | break; |
385 | 607 | } | 614 | } |
386 | 608 | } | 615 | } |
387 | 609 | } | 616 | } |
388 | @@ -622,24 +629,24 @@ | |||
389 | 622 | rem[remI] = base - 1 ) { | 629 | rem[remI] = base - 1 ) { |
390 | 623 | } | 630 | } |
391 | 624 | --rem[remI]; | 631 | --rem[remI]; |
393 | 625 | rem[remL] += base | 632 | rem[remL] += base; |
394 | 626 | } | 633 | } |
396 | 627 | rem[remL] -= dvsT[remL] | 634 | rem[remL] -= dvsT[remL]; |
397 | 628 | } | 635 | } |
398 | 629 | for ( ; !rem[0]; rem.shift() ) { | 636 | for ( ; !rem[0]; rem.shift() ) { |
399 | 630 | } | 637 | } |
400 | 631 | } else { | 638 | } else { |
402 | 632 | break | 639 | break; |
403 | 633 | } | 640 | } |
404 | 634 | } | 641 | } |
405 | 635 | 642 | ||
406 | 636 | // Add the 'next' digit to the result array. | ||
407 | 637 | qc[qi++] = cmp ? next : ++next; | ||
408 | 638 | |||
409 | 639 | // Update the remainder. | 643 | // Update the remainder. |
410 | 640 | rem[0] && cmp | 644 | rem[0] && cmp |
411 | 641 | ? ( rem[remL] = dvd[dvdI] || 0 ) | 645 | ? ( rem[remL] = dvd[dvdI] || 0 ) |
413 | 642 | : ( rem = [ dvd[dvdI] ] ) | 646 | : ( rem = [ dvd[dvdI] ] ); |
414 | 647 | |||
415 | 648 | // Add the 'next' digit to the result array. | ||
416 | 649 | qc[qi++] = cmp ? next : ++next; | ||
417 | 643 | 650 | ||
418 | 644 | } while ( ( dvdI++ < dvdL || rem[0] != null ) && s-- ); | 651 | } while ( ( dvdI++ < dvdL || rem[0] != null ) && s-- ); |
419 | 645 | 652 | ||
420 | @@ -648,28 +655,28 @@ | |||
421 | 648 | 655 | ||
422 | 649 | // There can't be more than one zero. | 656 | // There can't be more than one zero. |
423 | 650 | --quo['e']; | 657 | --quo['e']; |
425 | 651 | qc.shift() | 658 | qc.shift(); |
426 | 652 | } | 659 | } |
427 | 653 | 660 | ||
428 | 654 | // Round? | 661 | // Round? |
429 | 655 | if ( qi > dig ) { | 662 | if ( qi > dig ) { |
431 | 656 | rnd( quo, DECIMAL_PLACES, base, isOdd, rem[0] != null ) | 663 | rnd( quo, DECIMAL_PLACES, base, isOdd, rem[0] != null ); |
432 | 657 | } | 664 | } |
433 | 658 | 665 | ||
434 | 659 | // Overflow? | 666 | // Overflow? |
435 | 660 | if ( quo['e'] > MAX_EXP ) { | 667 | if ( quo['e'] > MAX_EXP ) { |
436 | 661 | 668 | ||
437 | 662 | // Infinity. | 669 | // Infinity. |
439 | 663 | quo['c'] = quo['e'] = null | 670 | quo['c'] = quo['e'] = null; |
440 | 664 | 671 | ||
441 | 665 | // Underflow? | 672 | // Underflow? |
442 | 666 | } else if ( quo['e'] < MIN_EXP ) { | 673 | } else if ( quo['e'] < MIN_EXP ) { |
443 | 667 | 674 | ||
444 | 668 | // Zero. | 675 | // Zero. |
446 | 669 | quo['c'] = [quo['e'] = 0] | 676 | quo['c'] = [quo['e'] = 0]; |
447 | 670 | } | 677 | } |
448 | 671 | 678 | ||
450 | 672 | return quo | 679 | return quo; |
451 | 673 | } | 680 | } |
452 | 674 | 681 | ||
453 | 675 | 682 | ||
454 | @@ -689,12 +696,12 @@ | |||
455 | 689 | 696 | ||
456 | 690 | // +-Infinity or NaN? | 697 | // +-Infinity or NaN? |
457 | 691 | if ( !c ) { | 698 | if ( !c ) { |
459 | 692 | return n['toS']() | 699 | return n['toS'](); |
460 | 693 | } | 700 | } |
461 | 694 | 701 | ||
462 | 695 | // Round? | 702 | // Round? |
463 | 696 | if ( c.length > ++d ) { | 703 | if ( c.length > ++d ) { |
465 | 697 | rnd( n, i, 10 ) | 704 | rnd( n, i, 10 ); |
466 | 698 | } | 705 | } |
467 | 699 | 706 | ||
468 | 700 | // Recalculate d if toFixed as n['e'] may have changed if value rounded up. | 707 | // Recalculate d if toFixed as n['e'] may have changed if value rounded up. |
469 | @@ -718,7 +725,7 @@ | |||
470 | 718 | : c[0] ) + ( i < 0 ? 'e' : 'e+' ) + i | 725 | : c[0] ) + ( i < 0 ? 'e' : 'e+' ) + i |
471 | 719 | 726 | ||
472 | 720 | // Normal notation. | 727 | // Normal notation. |
474 | 721 | : n['toS']() | 728 | : n['toS'](); |
475 | 722 | } | 729 | } |
476 | 723 | 730 | ||
477 | 724 | 731 | ||
478 | @@ -768,14 +775,14 @@ | |||
479 | 768 | 775 | ||
480 | 769 | // 1, 0.1, 0.01, 0.001, 0.0001 etc. | 776 | // 1, 0.1, 0.01, 0.001, 0.0001 etc. |
481 | 770 | xc[0] = 1; | 777 | xc[0] = 1; |
483 | 771 | x['e'] = -dp | 778 | x['e'] = -dp; |
484 | 772 | } else { | 779 | } else { |
485 | 773 | 780 | ||
486 | 774 | // Zero. | 781 | // Zero. |
488 | 775 | x['e'] = 0 | 782 | x['e'] = 0; |
489 | 776 | } | 783 | } |
490 | 777 | 784 | ||
492 | 778 | return x | 785 | return x; |
493 | 779 | } | 786 | } |
494 | 780 | 787 | ||
495 | 781 | // Remove any digits after the required decimal places. | 788 | // Remove any digits after the required decimal places. |
496 | @@ -790,7 +797,7 @@ | |||
497 | 790 | 797 | ||
498 | 791 | if ( !i-- ) { | 798 | if ( !i-- ) { |
499 | 792 | ++x['e']; | 799 | ++x['e']; |
501 | 793 | xc.unshift(1) | 800 | xc.unshift(1); |
502 | 794 | } | 801 | } |
503 | 795 | } | 802 | } |
504 | 796 | } | 803 | } |
505 | @@ -799,7 +806,7 @@ | |||
506 | 799 | for ( i = xc.length; !xc[--i]; xc.pop() ) { | 806 | for ( i = xc.length; !xc[--i]; xc.pop() ) { |
507 | 800 | } | 807 | } |
508 | 801 | 808 | ||
510 | 802 | return x | 809 | return x; |
511 | 803 | } | 810 | } |
512 | 804 | 811 | ||
513 | 805 | 812 | ||
514 | @@ -813,7 +820,7 @@ | |||
515 | 813 | x['c'] && rnd( x, dp, 10 ); | 820 | x['c'] && rnd( x, dp, 10 ); |
516 | 814 | ROUNDING_MODE = r; | 821 | ROUNDING_MODE = r; |
517 | 815 | 822 | ||
519 | 816 | return x | 823 | return x; |
520 | 817 | } | 824 | } |
521 | 818 | 825 | ||
522 | 819 | 826 | ||
523 | @@ -827,10 +834,10 @@ | |||
524 | 827 | var x = new BigNumber(this); | 834 | var x = new BigNumber(this); |
525 | 828 | 835 | ||
526 | 829 | if ( x['s'] < 0 ) { | 836 | if ( x['s'] < 0 ) { |
528 | 830 | x['s'] = 1 | 837 | x['s'] = 1; |
529 | 831 | } | 838 | } |
530 | 832 | 839 | ||
532 | 833 | return x | 840 | return x; |
533 | 834 | }; | 841 | }; |
534 | 835 | 842 | ||
535 | 836 | 843 | ||
536 | @@ -839,7 +846,7 @@ | |||
537 | 839 | * rounded to a whole number in the direction of Infinity. | 846 | * rounded to a whole number in the direction of Infinity. |
538 | 840 | */ | 847 | */ |
539 | 841 | P['ceil'] = function () { | 848 | P['ceil'] = function () { |
541 | 842 | return setMode( this, 0, 2 ) | 849 | return setMode( this, 0, 2 ); |
542 | 843 | }; | 850 | }; |
543 | 844 | 851 | ||
544 | 845 | 852 | ||
545 | @@ -862,29 +869,29 @@ | |||
546 | 862 | 869 | ||
547 | 863 | // Either NaN? | 870 | // Either NaN? |
548 | 864 | if ( !i || !j ) { | 871 | if ( !i || !j ) { |
550 | 865 | return null | 872 | return null; |
551 | 866 | } | 873 | } |
552 | 867 | 874 | ||
553 | 868 | a = xc && !xc[0], b = yc && !yc[0]; | 875 | a = xc && !xc[0], b = yc && !yc[0]; |
554 | 869 | 876 | ||
555 | 870 | // Either zero? | 877 | // Either zero? |
556 | 871 | if ( a || b ) { | 878 | if ( a || b ) { |
558 | 872 | return a ? b ? 0 : -j : i | 879 | return a ? b ? 0 : -j : i; |
559 | 873 | } | 880 | } |
560 | 874 | 881 | ||
561 | 875 | // Signs differ? | 882 | // Signs differ? |
562 | 876 | if ( i != j ) { | 883 | if ( i != j ) { |
564 | 877 | return i | 884 | return i; |
565 | 878 | } | 885 | } |
566 | 879 | 886 | ||
567 | 880 | // Either Infinity? | 887 | // Either Infinity? |
568 | 881 | if ( a = i < 0, b = k == l, !xc || !yc ) { | 888 | if ( a = i < 0, b = k == l, !xc || !yc ) { |
570 | 882 | return b ? 0 : !xc ^ a ? 1 : -1 | 889 | return b ? 0 : !xc ^ a ? 1 : -1; |
571 | 883 | } | 890 | } |
572 | 884 | 891 | ||
573 | 885 | // Compare exponents. | 892 | // Compare exponents. |
574 | 886 | if ( !b ) { | 893 | if ( !b ) { |
576 | 887 | return k > l ^ a ? 1 : -1 | 894 | return k > l ^ a ? 1 : -1; |
577 | 888 | } | 895 | } |
578 | 889 | 896 | ||
579 | 890 | // Compare digit by digit. | 897 | // Compare digit by digit. |
580 | @@ -893,11 +900,11 @@ | |||
581 | 893 | ++i < j; ) { | 900 | ++i < j; ) { |
582 | 894 | 901 | ||
583 | 895 | if ( xc[i] != yc[i] ) { | 902 | if ( xc[i] != yc[i] ) { |
585 | 896 | return xc[i] > yc[i] ^ a ? 1 : -1 | 903 | return xc[i] > yc[i] ^ a ? 1 : -1; |
586 | 897 | } | 904 | } |
587 | 898 | } | 905 | } |
588 | 899 | // Compare lengths. | 906 | // Compare lengths. |
590 | 900 | return k == l ? 0 : k > l ^ a ? 1 : -1 | 907 | return k == l ? 0 : k > l ^ a ? 1 : -1; |
591 | 901 | }; | 908 | }; |
592 | 902 | 909 | ||
593 | 903 | 910 | ||
594 | @@ -952,7 +959,7 @@ | |||
595 | 952 | // y is 0. Return +-Infinity. | 959 | // y is 0. Return +-Infinity. |
596 | 953 | : s / 0 ) | 960 | : s / 0 ) |
597 | 954 | 961 | ||
599 | 955 | : divide( xc, yc, xe - ye, s, 10 ) | 962 | : divide( xc, yc, xe - ye, s, 10 ); |
600 | 956 | }; | 963 | }; |
601 | 957 | 964 | ||
602 | 958 | 965 | ||
603 | @@ -962,7 +969,7 @@ | |||
604 | 962 | */ | 969 | */ |
605 | 963 | P['equals'] = P['eq'] = function ( n, b ) { | 970 | P['equals'] = P['eq'] = function ( n, b ) { |
606 | 964 | id = 3; | 971 | id = 3; |
608 | 965 | return this['cmp']( n, b ) === 0 | 972 | return this['cmp']( n, b ) === 0; |
609 | 966 | }; | 973 | }; |
610 | 967 | 974 | ||
611 | 968 | 975 | ||
612 | @@ -971,7 +978,7 @@ | |||
613 | 971 | * rounded to a whole number in the direction of -Infinity. | 978 | * rounded to a whole number in the direction of -Infinity. |
614 | 972 | */ | 979 | */ |
615 | 973 | P['floor'] = function () { | 980 | P['floor'] = function () { |
617 | 974 | return setMode( this, 0, 3 ) | 981 | return setMode( this, 0, 3 ); |
618 | 975 | }; | 982 | }; |
619 | 976 | 983 | ||
620 | 977 | 984 | ||
621 | @@ -981,7 +988,7 @@ | |||
622 | 981 | */ | 988 | */ |
623 | 982 | P['greaterThan'] = P['gt'] = function ( n, b ) { | 989 | P['greaterThan'] = P['gt'] = function ( n, b ) { |
624 | 983 | id = 4; | 990 | id = 4; |
626 | 984 | return this['cmp']( n, b ) > 0 | 991 | return this['cmp']( n, b ) > 0; |
627 | 985 | }; | 992 | }; |
628 | 986 | 993 | ||
629 | 987 | 994 | ||
630 | @@ -991,7 +998,7 @@ | |||
631 | 991 | */ | 998 | */ |
632 | 992 | P['greaterThanOrEqualTo'] = P['gte'] = function ( n, b ) { | 999 | P['greaterThanOrEqualTo'] = P['gte'] = function ( n, b ) { |
633 | 993 | id = 5; | 1000 | id = 5; |
635 | 994 | return ( b = this['cmp']( n, b ) ) == 1 || b === 0 | 1001 | return ( b = this['cmp']( n, b ) ) == 1 || b === 0; |
636 | 995 | }; | 1002 | }; |
637 | 996 | 1003 | ||
638 | 997 | 1004 | ||
639 | @@ -1000,7 +1007,7 @@ | |||
640 | 1000 | * returns false. | 1007 | * returns false. |
641 | 1001 | */ | 1008 | */ |
642 | 1002 | P['isFinite'] = P['isF'] = function () { | 1009 | P['isFinite'] = P['isF'] = function () { |
644 | 1003 | return !!this['c'] | 1010 | return !!this['c']; |
645 | 1004 | }; | 1011 | }; |
646 | 1005 | 1012 | ||
647 | 1006 | 1013 | ||
648 | @@ -1009,7 +1016,7 @@ | |||
649 | 1009 | * false. | 1016 | * false. |
650 | 1010 | */ | 1017 | */ |
651 | 1011 | P['isNaN'] = function () { | 1018 | P['isNaN'] = function () { |
653 | 1012 | return !this['s'] | 1019 | return !this['s']; |
654 | 1013 | }; | 1020 | }; |
655 | 1014 | 1021 | ||
656 | 1015 | 1022 | ||
657 | @@ -1018,7 +1025,7 @@ | |||
658 | 1018 | * returns false. | 1025 | * returns false. |
659 | 1019 | */ | 1026 | */ |
660 | 1020 | P['isNegative'] = P['isNeg'] = function () { | 1027 | P['isNegative'] = P['isNeg'] = function () { |
662 | 1021 | return this['s'] < 0 | 1028 | return this['s'] < 0; |
663 | 1022 | }; | 1029 | }; |
664 | 1023 | 1030 | ||
665 | 1024 | 1031 | ||
666 | @@ -1027,7 +1034,7 @@ | |||
667 | 1027 | * false. | 1034 | * false. |
668 | 1028 | */ | 1035 | */ |
669 | 1029 | P['isZero'] = P['isZ'] = function () { | 1036 | P['isZero'] = P['isZ'] = function () { |
671 | 1030 | return !!this['c'] && this['c'][0] == 0 | 1037 | return !!this['c'] && this['c'][0] == 0; |
672 | 1031 | }; | 1038 | }; |
673 | 1032 | 1039 | ||
674 | 1033 | 1040 | ||
675 | @@ -1037,7 +1044,7 @@ | |||
676 | 1037 | */ | 1044 | */ |
677 | 1038 | P['lessThan'] = P['lt'] = function ( n, b ) { | 1045 | P['lessThan'] = P['lt'] = function ( n, b ) { |
678 | 1039 | id = 6; | 1046 | id = 6; |
680 | 1040 | return this['cmp']( n, b ) < 0 | 1047 | return this['cmp']( n, b ) < 0; |
681 | 1041 | }; | 1048 | }; |
682 | 1042 | 1049 | ||
683 | 1043 | 1050 | ||
684 | @@ -1047,7 +1054,7 @@ | |||
685 | 1047 | */ | 1054 | */ |
686 | 1048 | P['lessThanOrEqualTo'] = P['lte'] = function ( n, b ) { | 1055 | P['lessThanOrEqualTo'] = P['lte'] = function ( n, b ) { |
687 | 1049 | id = 7; | 1056 | id = 7; |
689 | 1050 | return ( b = this['cmp']( n, b ) ) == -1 || b === 0 | 1057 | return ( b = this['cmp']( n, b ) ) == -1 || b === 0; |
690 | 1051 | }; | 1058 | }; |
691 | 1052 | 1059 | ||
692 | 1053 | 1060 | ||
693 | @@ -1080,12 +1087,12 @@ | |||
694 | 1080 | 1087 | ||
695 | 1081 | // Either NaN? | 1088 | // Either NaN? |
696 | 1082 | if ( !a || !b ) { | 1089 | if ( !a || !b ) { |
698 | 1083 | return new BigNumber(NaN) | 1090 | return new BigNumber(NaN); |
699 | 1084 | } | 1091 | } |
700 | 1085 | 1092 | ||
701 | 1086 | // Signs differ? | 1093 | // Signs differ? |
702 | 1087 | if ( a != b ) { | 1094 | if ( a != b ) { |
704 | 1088 | return y['s'] = -b, x['plus'](y) | 1095 | return y['s'] = -b, x['plus'](y); |
705 | 1089 | } | 1096 | } |
706 | 1090 | 1097 | ||
707 | 1091 | var xc = x['c'], | 1098 | var xc = x['c'], |
708 | @@ -1097,7 +1104,7 @@ | |||
709 | 1097 | 1104 | ||
710 | 1098 | // Either Infinity? | 1105 | // Either Infinity? |
711 | 1099 | if ( !xc || !yc ) { | 1106 | if ( !xc || !yc ) { |
713 | 1100 | return xc ? ( y['s'] = -b, y ) : new BigNumber( yc ? x : NaN ) | 1107 | return xc ? ( y['s'] = -b, y ) : new BigNumber( yc ? x : NaN ); |
714 | 1101 | } | 1108 | } |
715 | 1102 | 1109 | ||
716 | 1103 | // Either zero? | 1110 | // Either zero? |
717 | @@ -1113,7 +1120,7 @@ | |||
718 | 1113 | 1120 | ||
719 | 1114 | // Both are zero. | 1121 | // Both are zero. |
720 | 1115 | // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity | 1122 | // IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity |
722 | 1116 | : ROUNDING_MODE == 3 ? -0 : 0 ) | 1123 | : ROUNDING_MODE == 3 ? -0 : 0 ); |
723 | 1117 | } | 1124 | } |
724 | 1118 | } | 1125 | } |
725 | 1119 | 1126 | ||
726 | @@ -1124,7 +1131,7 @@ | |||
727 | 1124 | 1131 | ||
728 | 1125 | for ( d.reverse(), b = a; b--; d.push(0) ) { | 1132 | for ( d.reverse(), b = a; b--; d.push(0) ) { |
729 | 1126 | } | 1133 | } |
731 | 1127 | d.reverse() | 1134 | d.reverse(); |
732 | 1128 | } else { | 1135 | } else { |
733 | 1129 | 1136 | ||
734 | 1130 | // Exponents equal. Check digit by digit. | 1137 | // Exponents equal. Check digit by digit. |
735 | @@ -1134,7 +1141,7 @@ | |||
736 | 1134 | 1141 | ||
737 | 1135 | if ( xc[b] != yc[b] ) { | 1142 | if ( xc[b] != yc[b] ) { |
738 | 1136 | xLTy = xc[b] < yc[b]; | 1143 | xLTy = xc[b] < yc[b]; |
740 | 1137 | break | 1144 | break; |
741 | 1138 | } | 1145 | } |
742 | 1139 | } | 1146 | } |
743 | 1140 | } | 1147 | } |
744 | @@ -1142,7 +1149,7 @@ | |||
745 | 1142 | // x < y? Point xc to the array of the bigger number. | 1149 | // x < y? Point xc to the array of the bigger number. |
746 | 1143 | if ( xLTy ) { | 1150 | if ( xLTy ) { |
747 | 1144 | d = xc, xc = yc, yc = d; | 1151 | d = xc, xc = yc, yc = d; |
749 | 1145 | y['s'] = -y['s'] | 1152 | y['s'] = -y['s']; |
750 | 1146 | } | 1153 | } |
751 | 1147 | 1154 | ||
752 | 1148 | /* | 1155 | /* |
753 | @@ -1163,9 +1170,9 @@ | |||
754 | 1163 | for ( i = b; i && !xc[--i]; xc[i] = 9 ) { | 1170 | for ( i = b; i && !xc[--i]; xc[i] = 9 ) { |
755 | 1164 | } | 1171 | } |
756 | 1165 | --xc[i]; | 1172 | --xc[i]; |
758 | 1166 | xc[b] += 10 | 1173 | xc[b] += 10; |
759 | 1167 | } | 1174 | } |
761 | 1168 | xc[b] -= yc[b] | 1175 | xc[b] -= yc[b]; |
762 | 1169 | } | 1176 | } |
763 | 1170 | 1177 | ||
764 | 1171 | // Remove trailing zeros. | 1178 | // Remove trailing zeros. |
765 | @@ -1189,14 +1196,14 @@ | |||
766 | 1189 | * n - n = +0 but n - n = -0 when rounding towards -Infinity. | 1196 | * n - n = +0 but n - n = -0 when rounding towards -Infinity. |
767 | 1190 | */ | 1197 | */ |
768 | 1191 | if ( !xc[0] ) { | 1198 | if ( !xc[0] ) { |
770 | 1192 | y['s'] = ROUNDING_MODE == 3 ? -1 : 1 | 1199 | y['s'] = ROUNDING_MODE == 3 ? -1 : 1; |
771 | 1193 | } | 1200 | } |
772 | 1194 | 1201 | ||
773 | 1195 | // Result is zero. | 1202 | // Result is zero. |
775 | 1196 | xc = [ye = 0] | 1203 | xc = [ye = 0]; |
776 | 1197 | } | 1204 | } |
777 | 1198 | 1205 | ||
779 | 1199 | return y['c'] = xc, y['e'] = ye, y | 1206 | return y['c'] = xc, y['e'] = ye, y; |
780 | 1200 | }; | 1207 | }; |
781 | 1201 | 1208 | ||
782 | 1202 | 1209 | ||
783 | @@ -1225,7 +1232,7 @@ | |||
784 | 1225 | b = !i || !j || yc && !yc[0]; | 1232 | b = !i || !j || yc && !yc[0]; |
785 | 1226 | 1233 | ||
786 | 1227 | if ( b || xc && !xc[0] ) { | 1234 | if ( b || xc && !xc[0] ) { |
788 | 1228 | return new BigNumber( b ? NaN : x ) | 1235 | return new BigNumber( b ? NaN : x ); |
789 | 1229 | } | 1236 | } |
790 | 1230 | 1237 | ||
791 | 1231 | x['s'] = y['s'] = 1; | 1238 | x['s'] = y['s'] = 1; |
792 | @@ -1238,7 +1245,7 @@ | |||
793 | 1238 | DECIMAL_PLACES = 0, ROUNDING_MODE = 1, | 1245 | DECIMAL_PLACES = 0, ROUNDING_MODE = 1, |
794 | 1239 | x = x['div'](y), | 1246 | x = x['div'](y), |
795 | 1240 | DECIMAL_PLACES = i, ROUNDING_MODE = j, | 1247 | DECIMAL_PLACES = i, ROUNDING_MODE = j, |
797 | 1241 | this['minus']( x['times'](y) ) ) | 1248 | this['minus']( x['times'](y) ) ); |
798 | 1242 | }; | 1249 | }; |
799 | 1243 | 1250 | ||
800 | 1244 | 1251 | ||
801 | @@ -1249,7 +1256,7 @@ | |||
802 | 1249 | P['negated'] = P['neg'] = function () { | 1256 | P['negated'] = P['neg'] = function () { |
803 | 1250 | var x = new BigNumber(this); | 1257 | var x = new BigNumber(this); |
804 | 1251 | 1258 | ||
806 | 1252 | return x['s'] = -x['s'] || null, x | 1259 | return x['s'] = -x['s'] || null, x; |
807 | 1253 | }; | 1260 | }; |
808 | 1254 | 1261 | ||
809 | 1255 | 1262 | ||
810 | @@ -1282,12 +1289,12 @@ | |||
811 | 1282 | 1289 | ||
812 | 1283 | // Either NaN? | 1290 | // Either NaN? |
813 | 1284 | if ( !a || !b ) { | 1291 | if ( !a || !b ) { |
815 | 1285 | return new BigNumber(NaN) | 1292 | return new BigNumber(NaN); |
816 | 1286 | } | 1293 | } |
817 | 1287 | 1294 | ||
818 | 1288 | // Signs differ? | 1295 | // Signs differ? |
819 | 1289 | if ( a != b ) { | 1296 | if ( a != b ) { |
821 | 1290 | return y['s'] = -b, x['minus'](y) | 1297 | return y['s'] = -b, x['minus'](y); |
822 | 1291 | } | 1298 | } |
823 | 1292 | 1299 | ||
824 | 1293 | var xe = x['e'], | 1300 | var xe = x['e'], |
825 | @@ -1301,7 +1308,7 @@ | |||
826 | 1301 | if ( !xc || !yc ) { | 1308 | if ( !xc || !yc ) { |
827 | 1302 | 1309 | ||
828 | 1303 | // Return +-Infinity. | 1310 | // Return +-Infinity. |
830 | 1304 | return new BigNumber( a / 0 ) | 1311 | return new BigNumber( a / 0 ); |
831 | 1305 | } | 1312 | } |
832 | 1306 | 1313 | ||
833 | 1307 | // Either zero? | 1314 | // Either zero? |
834 | @@ -1316,7 +1323,7 @@ | |||
835 | 1316 | ? x | 1323 | ? x |
836 | 1317 | 1324 | ||
837 | 1318 | // Both are zero. Return zero. | 1325 | // Both are zero. Return zero. |
839 | 1319 | : a * 0 ) | 1326 | : a * 0 ); |
840 | 1320 | } | 1327 | } |
841 | 1321 | } | 1328 | } |
842 | 1322 | 1329 | ||
843 | @@ -1327,12 +1334,12 @@ | |||
844 | 1327 | 1334 | ||
845 | 1328 | for ( d.reverse(); a--; d.push(0) ) { | 1335 | for ( d.reverse(); a--; d.push(0) ) { |
846 | 1329 | } | 1336 | } |
848 | 1330 | d.reverse() | 1337 | d.reverse(); |
849 | 1331 | } | 1338 | } |
850 | 1332 | 1339 | ||
851 | 1333 | // Point xc to the longer array. | 1340 | // Point xc to the longer array. |
852 | 1334 | if ( xc.length - yc.length < 0 ) { | 1341 | if ( xc.length - yc.length < 0 ) { |
854 | 1335 | d = yc, yc = xc, xc = d | 1342 | d = yc, yc = xc, xc = d; |
855 | 1336 | } | 1343 | } |
856 | 1337 | 1344 | ||
857 | 1338 | /* | 1345 | /* |
858 | @@ -1352,7 +1359,7 @@ | |||
859 | 1352 | if ( ++ye > MAX_EXP ) { | 1359 | if ( ++ye > MAX_EXP ) { |
860 | 1353 | 1360 | ||
861 | 1354 | // Infinity. | 1361 | // Infinity. |
863 | 1355 | xc = ye = null | 1362 | xc = ye = null; |
864 | 1356 | } | 1363 | } |
865 | 1357 | } | 1364 | } |
866 | 1358 | 1365 | ||
867 | @@ -1360,7 +1367,7 @@ | |||
868 | 1360 | for ( a = xc.length; xc[--a] == 0; xc.pop() ) { | 1367 | for ( a = xc.length; xc[--a] == 0; xc.pop() ) { |
869 | 1361 | } | 1368 | } |
870 | 1362 | 1369 | ||
872 | 1363 | return y['c'] = xc, y['e'] = ye, y | 1370 | return y['c'] = xc, y['e'] = ye, y; |
873 | 1364 | }; | 1371 | }; |
874 | 1365 | 1372 | ||
875 | 1366 | 1373 | ||
876 | @@ -1399,23 +1406,23 @@ | |||
877 | 1399 | !i ) { | 1406 | !i ) { |
878 | 1400 | 1407 | ||
879 | 1401 | // i is +-Infinity, NaN or 0. | 1408 | // i is +-Infinity, NaN or 0. |
881 | 1402 | return new BigNumber( Math.pow( x['toS'](), i ) ) | 1409 | return new BigNumber( Math.pow( x['toS'](), i ) ); |
882 | 1403 | } | 1410 | } |
883 | 1404 | 1411 | ||
884 | 1405 | for ( i = i < 0 ? -i : i; ; ) { | 1412 | for ( i = i < 0 ? -i : i; ; ) { |
885 | 1406 | 1413 | ||
886 | 1407 | if ( i & 1 ) { | 1414 | if ( i & 1 ) { |
888 | 1408 | y = y['times'](x) | 1415 | y = y['times'](x); |
889 | 1409 | } | 1416 | } |
890 | 1410 | i >>= 1; | 1417 | i >>= 1; |
891 | 1411 | 1418 | ||
892 | 1412 | if ( !i ) { | 1419 | if ( !i ) { |
894 | 1413 | break | 1420 | break; |
895 | 1414 | } | 1421 | } |
897 | 1415 | x = x['times'](x) | 1422 | x = x['times'](x); |
898 | 1416 | } | 1423 | } |
899 | 1417 | 1424 | ||
901 | 1418 | return e < 0 ? ONE['div'](y) : y | 1425 | return e < 0 ? ONE['div'](y) : y; |
902 | 1419 | }; | 1426 | }; |
903 | 1420 | 1427 | ||
904 | 1421 | 1428 | ||
905 | @@ -1449,7 +1456,7 @@ | |||
906 | 1449 | ? ROUNDING_MODE | 1456 | ? ROUNDING_MODE |
907 | 1450 | : rm | 0; | 1457 | : rm | 0; |
908 | 1451 | 1458 | ||
910 | 1452 | return setMode( this, dp, rm ) | 1459 | return setMode( this, dp, rm ); |
911 | 1453 | }; | 1460 | }; |
912 | 1454 | 1461 | ||
913 | 1455 | 1462 | ||
914 | @@ -1465,7 +1472,7 @@ | |||
915 | 1465 | * this BigNumber, rounded according to DECIMAL_PLACES and ROUNDING_MODE. | 1472 | * this BigNumber, rounded according to DECIMAL_PLACES and ROUNDING_MODE. |
916 | 1466 | */ | 1473 | */ |
917 | 1467 | P['squareRoot'] = P['sqrt'] = function () { | 1474 | P['squareRoot'] = P['sqrt'] = function () { |
919 | 1468 | var i, n, r, re, t, | 1475 | var n, r, re, t, |
920 | 1469 | x = this, | 1476 | x = this, |
921 | 1470 | c = x['c'], | 1477 | c = x['c'], |
922 | 1471 | s = x['s'], | 1478 | s = x['s'], |
923 | @@ -1479,7 +1486,7 @@ | |||
924 | 1479 | 1486 | ||
925 | 1480 | return new BigNumber( !s || s < 0 && ( !c || c[0] ) | 1487 | return new BigNumber( !s || s < 0 && ( !c || c[0] ) |
926 | 1481 | ? NaN | 1488 | ? NaN |
928 | 1482 | : c ? x : 1 / 0 ) | 1489 | : c ? x : 1 / 0 ); |
929 | 1483 | } | 1490 | } |
930 | 1484 | 1491 | ||
931 | 1485 | // Initial estimate. | 1492 | // Initial estimate. |
932 | @@ -1494,23 +1501,23 @@ | |||
933 | 1494 | n = c.join(''); | 1501 | n = c.join(''); |
934 | 1495 | 1502 | ||
935 | 1496 | if ( !( n.length + e & 1 ) ) { | 1503 | if ( !( n.length + e & 1 ) ) { |
937 | 1497 | n += '0' | 1504 | n += '0'; |
938 | 1498 | } | 1505 | } |
939 | 1499 | r = new BigNumber( Math.sqrt(n) + '' ); | 1506 | r = new BigNumber( Math.sqrt(n) + '' ); |
940 | 1500 | 1507 | ||
941 | 1501 | // r may still not be finite. | 1508 | // r may still not be finite. |
942 | 1502 | if ( !r['c'] ) { | 1509 | if ( !r['c'] ) { |
944 | 1503 | r['c'] = [1] | 1510 | r['c'] = [1]; |
945 | 1504 | } | 1511 | } |
947 | 1505 | r['e'] = ( ( ( e + 1 ) / 2 ) | 0 ) - ( e < 0 || e & 1 ) | 1512 | r['e'] = ( ( ( e + 1 ) / 2 ) | 0 ) - ( e < 0 || e & 1 ); |
948 | 1506 | } else { | 1513 | } else { |
950 | 1507 | r = new BigNumber( n = s.toString() ) | 1514 | r = new BigNumber( n = s.toString() ); |
951 | 1508 | } | 1515 | } |
952 | 1509 | re = r['e']; | 1516 | re = r['e']; |
953 | 1510 | s = re + ( DECIMAL_PLACES += 4 ); | 1517 | s = re + ( DECIMAL_PLACES += 4 ); |
954 | 1511 | 1518 | ||
955 | 1512 | if ( s < 3 ) { | 1519 | if ( s < 3 ) { |
957 | 1513 | s = 0 | 1520 | s = 0; |
958 | 1514 | } | 1521 | } |
959 | 1515 | e = s; | 1522 | e = s; |
960 | 1516 | 1523 | ||
961 | @@ -1548,12 +1555,12 @@ | |||
962 | 1548 | ROUNDING_MODE = rm; | 1555 | ROUNDING_MODE = rm; |
963 | 1549 | DECIMAL_PLACES = dp; | 1556 | DECIMAL_PLACES = dp; |
964 | 1550 | 1557 | ||
966 | 1551 | return t | 1558 | return t; |
967 | 1552 | } | 1559 | } |
968 | 1553 | } | 1560 | } |
969 | 1554 | DECIMAL_PLACES += 4; | 1561 | DECIMAL_PLACES += 4; |
970 | 1555 | s += 4; | 1562 | s += 4; |
972 | 1556 | n = '' | 1563 | n = ''; |
973 | 1557 | } else { | 1564 | } else { |
974 | 1558 | 1565 | ||
975 | 1559 | /* | 1566 | /* |
976 | @@ -1566,21 +1573,21 @@ | |||
977 | 1566 | 1573 | ||
978 | 1567 | // Truncate to the first rounding digit. | 1574 | // Truncate to the first rounding digit. |
979 | 1568 | if ( c.length > e - 2 ) { | 1575 | if ( c.length > e - 2 ) { |
981 | 1569 | c.length = e - 2 | 1576 | c.length = e - 2; |
982 | 1570 | } | 1577 | } |
983 | 1571 | 1578 | ||
984 | 1572 | if ( !r['times'](r)['eq'](x) ) { | 1579 | if ( !r['times'](r)['eq'](x) ) { |
985 | 1573 | 1580 | ||
986 | 1574 | while ( c.length < e - 3 ) { | 1581 | while ( c.length < e - 3 ) { |
988 | 1575 | c.push(0) | 1582 | c.push(0); |
989 | 1576 | } | 1583 | } |
991 | 1577 | c[e - 3]++ | 1584 | c[e - 3]++; |
992 | 1578 | } | 1585 | } |
993 | 1579 | } | 1586 | } |
994 | 1580 | ROUNDING_MODE = rm; | 1587 | ROUNDING_MODE = rm; |
995 | 1581 | rnd( r, DECIMAL_PLACES = dp, 10 ); | 1588 | rnd( r, DECIMAL_PLACES = dp, 10 ); |
996 | 1582 | 1589 | ||
998 | 1583 | return r | 1590 | return r; |
999 | 1584 | } | 1591 | } |
1000 | 1585 | } | 1592 | } |
1001 | 1586 | } | 1593 | } |
1002 | @@ -1637,12 +1644,12 @@ | |||
1003 | 1637 | ? y['s'] / 0 | 1644 | ? y['s'] / 0 |
1004 | 1638 | 1645 | ||
1005 | 1639 | // x or y is 0. Return +-0. | 1646 | // x or y is 0. Return +-0. |
1007 | 1640 | : y['s'] * 0 ) | 1647 | : y['s'] * 0 ); |
1008 | 1641 | } | 1648 | } |
1009 | 1642 | y['e'] = i + j; | 1649 | y['e'] = i + j; |
1010 | 1643 | 1650 | ||
1011 | 1644 | if ( ( a = xc.length ) < ( b = yc.length ) ) { | 1651 | if ( ( a = xc.length ) < ( b = yc.length ) ) { |
1013 | 1645 | c = xc, xc = yc, yc = c, j = a, a = b, b = j | 1652 | c = xc, xc = yc, yc = c, j = a, a = b, b = j; |
1014 | 1646 | } | 1653 | } |
1015 | 1647 | 1654 | ||
1016 | 1648 | for ( j = a + b, c = []; j--; c.push(0) ) { | 1655 | for ( j = a + b, c = []; j--; c.push(0) ) { |
1017 | @@ -1659,7 +1666,7 @@ | |||
1018 | 1659 | } | 1666 | } |
1019 | 1660 | 1667 | ||
1020 | 1661 | if ( b ) { | 1668 | if ( b ) { |
1022 | 1662 | c[j] = ( c[j] + b ) % 10 | 1669 | c[j] = ( c[j] + b ) % 10; |
1023 | 1663 | } | 1670 | } |
1024 | 1664 | } | 1671 | } |
1025 | 1665 | 1672 | ||
1026 | @@ -1689,7 +1696,7 @@ | |||
1027 | 1689 | // Neither. | 1696 | // Neither. |
1028 | 1690 | : c; | 1697 | : c; |
1029 | 1691 | 1698 | ||
1031 | 1692 | return y | 1699 | return y; |
1032 | 1693 | }; | 1700 | }; |
1033 | 1694 | 1701 | ||
1034 | 1695 | 1702 | ||
1035 | @@ -1715,7 +1722,7 @@ | |||
1036 | 1715 | // 'toE() decimal places out of range: {dp}' | 1722 | // 'toE() decimal places out of range: {dp}' |
1037 | 1716 | !ifExceptionsThrow( dp, 'decimal places', 'toE' ) ) && this['c'] | 1723 | !ifExceptionsThrow( dp, 'decimal places', 'toE' ) ) && this['c'] |
1038 | 1717 | ? this['c'].length - 1 | 1724 | ? this['c'].length - 1 |
1040 | 1718 | : dp | 0, 1 ) | 1725 | : dp | 0, 1 ); |
1041 | 1719 | }; | 1726 | }; |
1042 | 1720 | 1727 | ||
1043 | 1721 | 1728 | ||
1044 | @@ -1739,7 +1746,7 @@ | |||
1045 | 1739 | // 'toF() decimal places not an integer: {dp}' | 1746 | // 'toF() decimal places not an integer: {dp}' |
1046 | 1740 | // 'toF() decimal places out of range: {dp}' | 1747 | // 'toF() decimal places out of range: {dp}' |
1047 | 1741 | !ifExceptionsThrow( dp, 'decimal places', 'toF' ) ) ) { | 1748 | !ifExceptionsThrow( dp, 'decimal places', 'toF' ) ) ) { |
1049 | 1742 | d = x['e'] + ( dp | 0 ) | 1749 | d = x['e'] + ( dp | 0 ); |
1050 | 1743 | } | 1750 | } |
1051 | 1744 | 1751 | ||
1052 | 1745 | n = TO_EXP_NEG, dp = TO_EXP_POS; | 1752 | n = TO_EXP_NEG, dp = TO_EXP_POS; |
1053 | @@ -1747,7 +1754,7 @@ | |||
1054 | 1747 | 1754 | ||
1055 | 1748 | // Note: str is initially undefined. | 1755 | // Note: str is initially undefined. |
1056 | 1749 | if ( d == str ) { | 1756 | if ( d == str ) { |
1058 | 1750 | str = x['toS']() | 1757 | str = x['toS'](); |
1059 | 1751 | } else { | 1758 | } else { |
1060 | 1752 | str = format( x, d ); | 1759 | str = format( x, d ); |
1061 | 1753 | 1760 | ||
1062 | @@ -1757,17 +1764,17 @@ | |||
1063 | 1757 | 1764 | ||
1064 | 1758 | // As e.g. -0 toFixed(3), will wrongly be returned as -0.000 from toString. | 1765 | // As e.g. -0 toFixed(3), will wrongly be returned as -0.000 from toString. |
1065 | 1759 | if ( !x['c'][0] ) { | 1766 | if ( !x['c'][0] ) { |
1067 | 1760 | str = str.replace(/^-/, '') | 1767 | str = str.replace(/^-/, ''); |
1068 | 1761 | 1768 | ||
1069 | 1762 | // As e.g. -0.5 if rounded to -0 will cause toString to omit the minus sign. | 1769 | // As e.g. -0.5 if rounded to -0 will cause toString to omit the minus sign. |
1070 | 1763 | } else if ( str.indexOf('-') < 0 ) { | 1770 | } else if ( str.indexOf('-') < 0 ) { |
1072 | 1764 | str = '-' + str | 1771 | str = '-' + str; |
1073 | 1765 | } | 1772 | } |
1074 | 1766 | } | 1773 | } |
1075 | 1767 | } | 1774 | } |
1076 | 1768 | TO_EXP_NEG = n, TO_EXP_POS = dp; | 1775 | TO_EXP_NEG = n, TO_EXP_POS = dp; |
1077 | 1769 | 1776 | ||
1079 | 1770 | return str | 1777 | return str; |
1080 | 1771 | }; | 1778 | }; |
1081 | 1772 | 1779 | ||
1082 | 1773 | 1780 | ||
1083 | @@ -1794,7 +1801,7 @@ | |||
1084 | 1794 | 1801 | ||
1085 | 1795 | // NaN, Infinity. | 1802 | // NaN, Infinity. |
1086 | 1796 | if ( !xc ) { | 1803 | if ( !xc ) { |
1088 | 1797 | return x['toS']() | 1804 | return x['toS'](); |
1089 | 1798 | } | 1805 | } |
1090 | 1799 | 1806 | ||
1091 | 1800 | e = d['e'] = xc.length - x['e'] - 1; | 1807 | e = d['e'] = xc.length - x['e'] - 1; |
1092 | @@ -1819,7 +1826,7 @@ | |||
1093 | 1819 | ( maxD = n )['cmp'](d) > 0 ) { | 1826 | ( maxD = n )['cmp'](d) > 0 ) { |
1094 | 1820 | 1827 | ||
1095 | 1821 | // d is e.g. 10, 100, 1000, 10000... , n1 is 1. | 1828 | // d is e.g. 10, 100, 1000, 10000... , n1 is 1. |
1097 | 1822 | maxD = e > 0 ? d : n1 | 1829 | maxD = e > 0 ? d : n1; |
1098 | 1823 | } | 1830 | } |
1099 | 1824 | 1831 | ||
1100 | 1825 | MAX_EXP = 1 / 0; | 1832 | MAX_EXP = 1 / 0; |
1101 | @@ -1830,7 +1837,7 @@ | |||
1102 | 1830 | d2 = d0['plus']( q['times'](d1) ); | 1837 | d2 = d0['plus']( q['times'](d1) ); |
1103 | 1831 | 1838 | ||
1104 | 1832 | if ( d2['cmp'](maxD) == 1 ) { | 1839 | if ( d2['cmp'](maxD) == 1 ) { |
1106 | 1833 | break | 1840 | break; |
1107 | 1834 | } | 1841 | } |
1108 | 1835 | 1842 | ||
1109 | 1836 | d0 = d1, d1 = d2; | 1843 | d0 = d1, d1 = d2; |
1110 | @@ -1839,7 +1846,7 @@ | |||
1111 | 1839 | n0 = d2; | 1846 | n0 = d2; |
1112 | 1840 | 1847 | ||
1113 | 1841 | d = n['minus']( q['times']( d2 = d ) ); | 1848 | d = n['minus']( q['times']( d2 = d ) ); |
1115 | 1842 | n = d2 | 1849 | n = d2; |
1116 | 1843 | } | 1850 | } |
1117 | 1844 | 1851 | ||
1118 | 1845 | d2 = maxD['minus'](d0)['div'](d1); | 1852 | d2 = maxD['minus'](d0)['div'](d1); |
1119 | @@ -1857,7 +1864,7 @@ | |||
1120 | 1857 | ? [ n1['toS'](), d1['toS']() ] | 1864 | ? [ n1['toS'](), d1['toS']() ] |
1121 | 1858 | : [ n0['toS'](), d0['toS']() ]; | 1865 | : [ n0['toS'](), d0['toS']() ]; |
1122 | 1859 | 1866 | ||
1124 | 1860 | return MAX_EXP = exp, DECIMAL_PLACES = dp, frac | 1867 | return MAX_EXP = exp, DECIMAL_PLACES = dp, frac; |
1125 | 1861 | }; | 1868 | }; |
1126 | 1862 | 1869 | ||
1127 | 1863 | 1870 | ||
1128 | @@ -1883,7 +1890,7 @@ | |||
1129 | 1883 | // 'toP() precision out of range: {sd}' | 1890 | // 'toP() precision out of range: {sd}' |
1130 | 1884 | !ifExceptionsThrow( sd, 'precision', 'toP' ) ) | 1891 | !ifExceptionsThrow( sd, 'precision', 'toP' ) ) |
1131 | 1885 | ? this['toS']() | 1892 | ? this['toS']() |
1133 | 1886 | : format( this, --sd | 0, 2 ) | 1893 | : format( this, --sd | 0, 2 ); |
1134 | 1887 | }; | 1894 | }; |
1135 | 1888 | 1895 | ||
1136 | 1889 | 1896 | ||
1137 | @@ -1904,11 +1911,11 @@ | |||
1138 | 1904 | 1911 | ||
1139 | 1905 | // Infinity or NaN? | 1912 | // Infinity or NaN? |
1140 | 1906 | if ( xe === null ) { | 1913 | if ( xe === null ) { |
1142 | 1907 | str = x['s'] ? 'Infinity' : 'NaN' | 1914 | str = x['s'] ? 'Infinity' : 'NaN'; |
1143 | 1908 | 1915 | ||
1144 | 1909 | // Exponential format? | 1916 | // Exponential format? |
1145 | 1910 | } else if ( b === u && ( xe <= TO_EXP_NEG || xe >= TO_EXP_POS ) ) { | 1917 | } else if ( b === u && ( xe <= TO_EXP_NEG || xe >= TO_EXP_POS ) ) { |
1147 | 1911 | return format( x, x['c'].length - 1, 1 ) | 1918 | return format( x, x['c'].length - 1, 1 ); |
1148 | 1912 | } else { | 1919 | } else { |
1149 | 1913 | str = x['c'].join(''); | 1920 | str = x['c'].join(''); |
1150 | 1914 | 1921 | ||
1151 | @@ -1918,7 +1925,7 @@ | |||
1152 | 1918 | // Prepend zeros. | 1925 | // Prepend zeros. |
1153 | 1919 | for ( ; ++xe; str = '0' + str ) { | 1926 | for ( ; ++xe; str = '0' + str ) { |
1154 | 1920 | } | 1927 | } |
1156 | 1921 | str = '0.' + str | 1928 | str = '0.' + str; |
1157 | 1922 | 1929 | ||
1158 | 1923 | // Positive exponent? | 1930 | // Positive exponent? |
1159 | 1924 | } else if ( strL = str.length, xe > 0 ) { | 1931 | } else if ( strL = str.length, xe > 0 ) { |
1160 | @@ -1929,17 +1936,17 @@ | |||
1161 | 1929 | for ( xe -= strL; xe-- ; str += '0' ) { | 1936 | for ( xe -= strL; xe-- ; str += '0' ) { |
1162 | 1930 | } | 1937 | } |
1163 | 1931 | } else if ( xe < strL ) { | 1938 | } else if ( xe < strL ) { |
1165 | 1932 | str = str.slice( 0, xe ) + '.' + str.slice(xe) | 1939 | str = str.slice( 0, xe ) + '.' + str.slice(xe); |
1166 | 1933 | } | 1940 | } |
1167 | 1934 | 1941 | ||
1168 | 1935 | // Exponent zero. | 1942 | // Exponent zero. |
1169 | 1936 | } else { | 1943 | } else { |
1170 | 1937 | if ( u = str.charAt(0), strL > 1 ) { | 1944 | if ( u = str.charAt(0), strL > 1 ) { |
1172 | 1938 | str = u + '.' + str.slice(1) | 1945 | str = u + '.' + str.slice(1); |
1173 | 1939 | 1946 | ||
1174 | 1940 | // Avoid '-0' | 1947 | // Avoid '-0' |
1175 | 1941 | } else if ( u == '0' ) { | 1948 | } else if ( u == '0' ) { |
1177 | 1942 | return u | 1949 | return u; |
1178 | 1943 | } | 1950 | } |
1179 | 1944 | } | 1951 | } |
1180 | 1945 | 1952 | ||
1181 | @@ -1951,19 +1958,31 @@ | |||
1182 | 1951 | 1958 | ||
1183 | 1952 | // Avoid '-0' | 1959 | // Avoid '-0' |
1184 | 1953 | if ( str == '0' ) { | 1960 | if ( str == '0' ) { |
1186 | 1954 | return str | 1961 | return str; |
1187 | 1955 | } | 1962 | } |
1188 | 1956 | } else { | 1963 | } else { |
1189 | 1957 | 1964 | ||
1190 | 1958 | // 'toS() base not an integer: {b}' | 1965 | // 'toS() base not an integer: {b}' |
1191 | 1959 | // 'toS() base out of range: {b}' | 1966 | // 'toS() base out of range: {b}' |
1193 | 1960 | ifExceptionsThrow( b, 'base', 'toS' ) | 1967 | ifExceptionsThrow( b, 'base', 'toS' ); |
1194 | 1961 | } | 1968 | } |
1195 | 1962 | } | 1969 | } |
1196 | 1963 | 1970 | ||
1197 | 1964 | } | 1971 | } |
1198 | 1965 | 1972 | ||
1200 | 1966 | return x['s'] < 0 ? '-' + str : str | 1973 | return x['s'] < 0 ? '-' + str : str; |
1201 | 1974 | }; | ||
1202 | 1975 | |||
1203 | 1976 | |||
1204 | 1977 | /* | ||
1205 | 1978 | * Return the value of this BigNumber converted to a number primitive. | ||
1206 | 1979 | * | ||
1207 | 1980 | */ | ||
1208 | 1981 | P['toNumber'] = P['toN'] = function () { | ||
1209 | 1982 | var x = this; | ||
1210 | 1983 | |||
1211 | 1984 | // Ensure zero has correct sign. | ||
1212 | 1985 | return +x || ( x['s'] ? 0 * x['s'] : NaN ); | ||
1213 | 1967 | }; | 1986 | }; |
1214 | 1968 | 1987 | ||
1215 | 1969 | 1988 | ||
1216 | @@ -1971,7 +1990,7 @@ | |||
1217 | 1971 | * Return as toString, but do not accept a base argument. | 1990 | * Return as toString, but do not accept a base argument. |
1218 | 1972 | */ | 1991 | */ |
1219 | 1973 | P['valueOf'] = function () { | 1992 | P['valueOf'] = function () { |
1221 | 1974 | return this['toS']() | 1993 | return this['toS'](); |
1222 | 1975 | }; | 1994 | }; |
1223 | 1976 | 1995 | ||
1224 | 1977 | 1996 | ||
1225 | @@ -1990,13 +2009,13 @@ | |||
1226 | 1990 | 2009 | ||
1227 | 1991 | // Node and other CommonJS-like environments that support module.exports. | 2010 | // Node and other CommonJS-like environments that support module.exports. |
1228 | 1992 | if ( typeof module !== 'undefined' && module.exports ) { | 2011 | if ( typeof module !== 'undefined' && module.exports ) { |
1230 | 1993 | module.exports = BigNumber | 2012 | module.exports = BigNumber; |
1231 | 1994 | 2013 | ||
1232 | 1995 | //AMD. | 2014 | //AMD. |
1233 | 1996 | } else if ( typeof define == 'function' && define.amd ) { | 2015 | } else if ( typeof define == 'function' && define.amd ) { |
1234 | 1997 | define( function () { | 2016 | define( function () { |
1237 | 1998 | return BigNumber | 2017 | return BigNumber; |
1238 | 1999 | }) | 2018 | }); |
1239 | 2000 | 2019 | ||
1240 | 2001 | //Browser. | 2020 | //Browser. |
1241 | 2002 | } else { | 2021 | } else { |
1242 | @@ -2004,4 +2023,3 @@ | |||
1243 | 2004 | } | 2023 | } |
1244 | 2005 | 2024 | ||
1245 | 2006 | })( this ); | 2025 | })( this ); |
1246 | 2007 |
PASSED: Continuous integration, rev:284 91.189. 93.70:8080/ job/ubuntu- calculator- app-ci/ 220/ 91.189. 93.70:8080/ job/generic- mediumtests- utopic/ 735 91.189. 93.70:8080/ job/generic- mediumtests- utopic/ 735/artifact/ work/output/ *zip*/output. zip 91.189. 93.70:8080/ job/ubuntu- calculator- app-utopic- amd64-ci/ 15
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: 91.189. 93.70:8080/ job/ubuntu- calculator- app-ci/ 220/rebuild
http://