long-decimal 0.00.10 → 0.00.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.html +12 -5
- data/doc/classes/LongDecimalRoundingMode/RoundingModeClass.src/M000136.html +22 -0
- data/doc/classes/LongMath/LongDecimal.html +1624 -0
- data/doc/classes/LongMath/LongDecimal.src/M000061.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000062.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000063.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000064.html +20 -0
- data/doc/classes/LongMath/LongDecimal.src/M000065.html +109 -0
- data/doc/classes/LongMath/LongDecimal.src/M000066.html +34 -0
- data/doc/classes/LongMath/LongDecimal.src/M000067.html +41 -0
- data/doc/classes/LongMath/LongDecimal.src/M000068.html +35 -0
- data/doc/classes/LongMath/LongDecimal.src/M000069.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000070.html +29 -0
- data/doc/classes/LongMath/LongDecimal.src/M000071.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000072.html +38 -0
- data/doc/classes/LongMath/LongDecimal.src/M000073.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000074.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000075.html +20 -0
- data/doc/classes/LongMath/LongDecimal.src/M000076.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000077.html +29 -0
- data/doc/classes/LongMath/LongDecimal.src/M000078.html +46 -0
- data/doc/classes/LongMath/LongDecimal.src/M000079.html +29 -0
- data/doc/classes/LongMath/LongDecimal.src/M000080.html +27 -0
- data/doc/classes/LongMath/LongDecimal.src/M000081.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000083.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000084.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000085.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000086.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000087.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000089.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000090.html +22 -0
- data/doc/classes/LongMath/LongDecimal.src/M000091.html +23 -0
- data/doc/classes/LongMath/LongDecimal.src/M000092.html +23 -0
- data/doc/classes/LongMath/LongDecimal.src/M000093.html +23 -0
- data/doc/classes/LongMath/LongDecimal.src/M000094.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000095.html +29 -0
- data/doc/classes/LongMath/LongDecimal.src/M000096.html +23 -0
- data/doc/classes/LongMath/LongDecimal.src/M000097.html +23 -0
- data/doc/classes/LongMath/LongDecimal.src/M000098.html +34 -0
- data/doc/classes/LongMath/LongDecimal.src/M000099.html +22 -0
- data/doc/classes/LongMath/LongDecimal.src/M000100.html +19 -0
- data/doc/classes/LongMath/LongDecimal.src/M000101.html +23 -0
- data/doc/classes/LongMath/LongDecimal.src/M000102.html +23 -0
- data/doc/classes/LongMath/LongDecimal.src/M000103.html +23 -0
- data/doc/classes/LongMath/LongDecimal.src/M000104.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000105.html +21 -0
- data/doc/classes/LongMath/LongDecimal.src/M000106.html +21 -0
- data/doc/classes/LongMath/LongDecimal.src/M000107.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000108.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000109.html +23 -0
- data/doc/classes/LongMath/LongDecimal.src/M000110.html +23 -0
- data/doc/classes/LongMath/LongDecimal.src/M000111.html +19 -0
- data/doc/classes/LongMath/LongDecimal.src/M000112.html +23 -0
- data/doc/classes/LongMath/LongDecimal.src/M000113.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000114.html +30 -0
- data/doc/classes/LongMath/LongDecimal.src/M000115.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000116.html +23 -0
- data/doc/classes/LongMath/LongDecimal.src/M000117.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000118.html +30 -0
- data/doc/classes/LongMath/LongDecimal.src/M000119.html +23 -0
- data/doc/classes/LongMath/LongDecimal.src/M000120.html +19 -0
- data/doc/classes/LongMath/LongDecimal.src/M000121.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000122.html +47 -0
- data/doc/classes/LongMath/LongDecimal.src/M000123.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000124.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000125.html +47 -0
- data/doc/classes/LongMath/LongDecimal.src/M000126.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000127.html +19 -0
- data/doc/classes/LongMath/LongDecimal.src/M000130.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000131.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000132.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000133.html +18 -0
- data/doc/classes/LongMath/LongDecimal.src/M000134.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.html +797 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000024.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000025.html +28 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000026.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000027.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000028.html +19 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000029.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000030.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000031.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000032.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000033.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000034.html +22 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000035.html +23 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000036.html +23 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000037.html +23 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000038.html +23 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000039.html +35 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000040.html +22 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000041.html +19 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000042.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000043.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000044.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000045.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000046.html +77 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000047.html +36 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000048.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000049.html +23 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000050.html +19 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000051.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000052.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000053.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000054.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000055.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000058.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000059.html +18 -0
- data/doc/classes/LongMath/LongDecimalQuot.src/M000060.html +18 -0
- data/doc/classes/LongMath/Numeric.html +150 -0
- data/doc/classes/LongMath/Numeric.src/M000135.html +18 -0
- data/doc/classes/LongMath.html +70 -37
- data/doc/classes/LongMath.src/M000001.html +19 -0
- data/doc/classes/LongMath.src/M000002.html +18 -0
- data/doc/classes/LongMath.src/M000003.html +18 -0
- data/doc/classes/LongMath.src/M000004.html +19 -0
- data/doc/classes/LongMath.src/M000005.html +18 -0
- data/doc/classes/LongMath.src/M000006.html +32 -0
- data/doc/classes/LongMath.src/M000007.html +32 -0
- data/doc/classes/LongMath.src/M000008.html +19 -0
- data/doc/classes/LongMath.src/M000009.html +43 -0
- data/doc/classes/LongMath.src/M000010.html +19 -0
- data/doc/classes/LongMath.src/M000011.html +73 -0
- data/doc/classes/LongMath.src/M000012.html +35 -0
- data/doc/classes/LongMath.src/M000013.html +50 -0
- data/doc/classes/LongMath.src/M000014.html +47 -0
- data/doc/classes/LongMath.src/M000015.html +22 -0
- data/doc/classes/LongMath.src/M000016.html +25 -0
- data/doc/classes/LongMath.src/M000017.html +107 -0
- data/doc/classes/LongMath.src/M000018.html +21 -0
- data/doc/classes/LongMath.src/M000019.html +30 -0
- data/doc/classes/LongMath.src/M000020.html +30 -0
- data/doc/classes/LongMath.src/M000021.html +115 -0
- data/doc/classes/LongMath.src/M000022.html +22 -0
- data/doc/classes/LongMath.src/M000023.html +18 -0
- data/doc/created.rid +1 -1
- data/doc/files/lib/longdecimal_rb.html +2 -2
- data/doc/fr_method_index.html +108 -111
- data/lib/longdecimal.rb +333 -93
- metadata +139 -2
data/doc/classes/LongMath.html
CHANGED
@@ -84,10 +84,13 @@
|
|
84
84
|
|
85
85
|
<div id="description">
|
86
86
|
<p>
|
87
|
-
|
88
|
-
|
89
|
-
href="LongMath.html#
|
90
|
-
|
87
|
+
<a href="LongMath.html">LongMath</a> provides some helper functions to
|
88
|
+
support <a href="LongMath.html#M000022">LongDecimal</a> and <a
|
89
|
+
href="LongMath.html#M000023">LongDecimalQuot</a>, mostly operating on
|
90
|
+
integers. They are used internally here, but possibly they can be used
|
91
|
+
elsewhere as well. In addition <a href="LongMath.html">LongMath</a>
|
92
|
+
provides methods like those in Math, but for <a
|
93
|
+
href="LongMath.html#M000022">LongDecimal</a> instead of Float.
|
91
94
|
</p>
|
92
95
|
|
93
96
|
</div>
|
@@ -189,10 +192,13 @@ Class <a href="LongMath/Numeric.html" class="link">LongMath::Numeric</a><br />
|
|
189
192
|
<div class="method-description">
|
190
193
|
<p>
|
191
194
|
method for calculating pi to the given number of digits after the decimal
|
192
|
-
point works fine for 1000 or 2000 digits or so.
|
195
|
+
point. It works fine for 1000 or 2000 digits or so. This method could be
|
193
196
|
optimized more, but if you really want to go for more digits, you will find
|
194
|
-
a specialized and optimized program for this specific purpose
|
195
|
-
|
197
|
+
a specialized and optimized program for this specific purpose, probably
|
198
|
+
written in C or C++. Since calculation of pi is not what should typically
|
199
|
+
be done with <a href="LongMath.html#M000022">LongDecimal</a>, you may
|
200
|
+
consider this method to be the easter egg of <a
|
201
|
+
href="LongMath.html#M000022">LongDecimal</a>. ;-)
|
196
202
|
</p>
|
197
203
|
</div>
|
198
204
|
</div>
|
@@ -209,7 +215,7 @@ easter egg ;-) )
|
|
209
215
|
|
210
216
|
<div class="method-description">
|
211
217
|
<p>
|
212
|
-
helper method: checks if parameter x is an Integer
|
218
|
+
helper method for internal use: checks if parameter x is an Integer
|
213
219
|
</p>
|
214
220
|
</div>
|
215
221
|
</div>
|
@@ -226,7 +232,7 @@ helper method: checks if parameter x is an Integer
|
|
226
232
|
|
227
233
|
<div class="method-description">
|
228
234
|
<p>
|
229
|
-
helper method: checks if parameter x is a <a
|
235
|
+
helper method for internal use: checks if parameter x is a <a
|
230
236
|
href="LongMath.html#M000022">LongDecimal</a>
|
231
237
|
</p>
|
232
238
|
</div>
|
@@ -244,8 +250,8 @@ href="LongMath.html#M000022">LongDecimal</a>
|
|
244
250
|
|
245
251
|
<div class="method-description">
|
246
252
|
<p>
|
247
|
-
helper method: checks if parameter x is a
|
248
|
-
|
253
|
+
helper method for internal use: checks if parameter x is a rounding mode
|
254
|
+
(instance of RoundingModeClass)
|
249
255
|
</p>
|
250
256
|
</div>
|
251
257
|
</div>
|
@@ -262,7 +268,8 @@ href="LongMath.html#M000022">LongDecimal</a>
|
|
262
268
|
|
263
269
|
<div class="method-description">
|
264
270
|
<p>
|
265
|
-
helper method: checks if parameter x is a
|
271
|
+
helper method for internal use: checks if parameter x is a reasonable value
|
272
|
+
for the precision (scale) of a <a
|
266
273
|
href="LongMath.html#M000022">LongDecimal</a>
|
267
274
|
</p>
|
268
275
|
</div>
|
@@ -280,8 +287,8 @@ href="LongMath.html#M000022">LongDecimal</a>
|
|
280
287
|
|
281
288
|
<div class="method-description">
|
282
289
|
<p>
|
283
|
-
helper method: checks if word_len is
|
284
|
-
into parts
|
290
|
+
helper method for internal use: checks if word_len is a reasonable size for
|
291
|
+
splitting a number into parts
|
285
292
|
</p>
|
286
293
|
</div>
|
287
294
|
</div>
|
@@ -300,7 +307,10 @@ into parts
|
|
300
307
|
<p>
|
301
308
|
calc the exponential function of x to the given precision as <a
|
302
309
|
href="LongMath.html#M000022">LongDecimal</a>. Only supports values of x
|
303
|
-
such that the result still fits into a float (x <= 709)
|
310
|
+
such that the result still fits into a float (x <= 709). This limitation
|
311
|
+
is somewhat arbitrary, but it is enforced in order to avoid producing
|
312
|
+
numbers with the exponential function that exceed the memory. It may be
|
313
|
+
removed in future versions.
|
304
314
|
</p>
|
305
315
|
</div>
|
306
316
|
</div>
|
@@ -337,8 +347,8 @@ if the default settings for the parameters do not work correctly
|
|
337
347
|
|
338
348
|
<div class="method-description">
|
339
349
|
<p>
|
340
|
-
find the gcd of x with b
|
341
|
-
that gcd(x, b
|
350
|
+
find the gcd of an Integer x with b**n0 where n0 is a sufficiently high
|
351
|
+
exponent such that gcd(x, b**m) = gcd(x, b**n) for all m, n >= n0
|
342
352
|
</p>
|
343
353
|
</div>
|
344
354
|
</div>
|
@@ -355,7 +365,7 @@ that gcd(x, b^m) = gcd(x, b^n) for all m, n > n0
|
|
355
365
|
|
356
366
|
<div class="method-description">
|
357
367
|
<p>
|
358
|
-
|
368
|
+
calculate the natural logarithm function of x to the given precision as <a
|
359
369
|
href="LongMath.html#M000022">LongDecimal</a>.
|
360
370
|
</p>
|
361
371
|
</div>
|
@@ -373,7 +383,7 @@ href="LongMath.html#M000022">LongDecimal</a>.
|
|
373
383
|
|
374
384
|
<div class="method-description">
|
375
385
|
<p>
|
376
|
-
|
386
|
+
calculate the base 10 logarithm of x to the given precision as <a
|
377
387
|
href="LongMath.html#M000022">LongDecimal</a>.
|
378
388
|
</p>
|
379
389
|
</div>
|
@@ -391,7 +401,7 @@ href="LongMath.html#M000022">LongDecimal</a>.
|
|
391
401
|
|
392
402
|
<div class="method-description">
|
393
403
|
<p>
|
394
|
-
|
404
|
+
calculate the base 2 logarithm of x to the given precision as <a
|
395
405
|
href="LongMath.html#M000022">LongDecimal</a>.
|
396
406
|
</p>
|
397
407
|
</div>
|
@@ -429,7 +439,8 @@ if the default settings for the parameters do not work correctly
|
|
429
439
|
|
430
440
|
<div class="method-description">
|
431
441
|
<p>
|
432
|
-
concatenate numbers given in words as bit patterns
|
442
|
+
concatenate numbers given in words as bit patterns (the opposite of <a
|
443
|
+
href="LongMath.html#M000006">split_to_words</a>)
|
433
444
|
</p>
|
434
445
|
</div>
|
435
446
|
</div>
|
@@ -446,9 +457,12 @@ concatenate numbers given in words as bit patterns
|
|
446
457
|
|
447
458
|
<div class="method-description">
|
448
459
|
<p>
|
449
|
-
|
450
|
-
Only works for prime numbers
|
451
|
-
|
460
|
+
Find the exponent of the highest power of prime number p that divides the
|
461
|
+
Integer x. Only works for prime numbers p (parameter prime_number). The
|
462
|
+
caller has to make sure that p (parameter prime_number) is actually a prime
|
463
|
+
number, because checks for primality actually cost something and should not
|
464
|
+
be duplicated more than necessary. This method works even for numbers x
|
465
|
+
that exceed the range of Float
|
452
466
|
</p>
|
453
467
|
</div>
|
454
468
|
</div>
|
@@ -484,8 +498,9 @@ such that exp(y) still fits into a float (y <= 709)
|
|
484
498
|
|
485
499
|
<div class="method-description">
|
486
500
|
<p>
|
487
|
-
split number x into parts of word_len bits each such that the
|
488
|
-
of these parts as bit patterns is x
|
501
|
+
split number (Integer) x into parts of word_len bits each such that the
|
502
|
+
concatenation of these parts as bit patterns is x (the opposite of <a
|
503
|
+
href="LongMath.html#M000007">merge_from_words</a>)
|
489
504
|
</p>
|
490
505
|
</div>
|
491
506
|
</div>
|
@@ -502,7 +517,8 @@ of these parts as bit patterns is x
|
|
502
517
|
|
503
518
|
<div class="method-description">
|
504
519
|
<p>
|
505
|
-
calculate the square root of an integer using bitwise algorithm
|
520
|
+
calculate the square root of an integer x using bitwise algorithm the
|
521
|
+
result is rounded to an integer y such that y**2�<=�x�<�(y+1)**2
|
506
522
|
</p>
|
507
523
|
</div>
|
508
524
|
</div>
|
@@ -519,10 +535,13 @@ calculate the square root of an integer using bitwise algorithm
|
|
519
535
|
|
520
536
|
<div class="method-description">
|
521
537
|
<p>
|
522
|
-
calculate
|
523
|
-
s**2
|
524
|
-
well for relatively small values of x.
|
538
|
+
�calculate�the�an�integer�s�>=�0�and�a�remainder�r�>=�0�such�that
|
539
|
+
�x�=�s**2�+�r�and�s**2�<=�x�<�(s+1)**2
|
525
540
|
</p>
|
541
|
+
<pre>
|
542
|
+
the bitwise algorithm is used, which works well for relatively
|
543
|
+
small values of x.
|
544
|
+
</pre>
|
526
545
|
</div>
|
527
546
|
</div>
|
528
547
|
|
@@ -538,7 +557,11 @@ well for relatively small values of x.
|
|
538
557
|
|
539
558
|
<div class="method-description">
|
540
559
|
<p>
|
541
|
-
calculate the square root of an integer using larger chunks of the number
|
560
|
+
calculate the square root of an integer using larger chunks of the number.
|
561
|
+
The optional parameter n provides the size of these chunks. It is by
|
562
|
+
default chosen to be 16, which is optimized for 32 bit systems, because
|
563
|
+
internally parts of the double size are used. the result is rounded to an
|
564
|
+
integer y such that y**2�<=�x�<�(y+1)**2
|
542
565
|
</p>
|
543
566
|
</div>
|
544
567
|
</div>
|
@@ -554,13 +577,18 @@ calculate the square root of an integer using larger chunks of the number
|
|
554
577
|
</div>
|
555
578
|
|
556
579
|
<div class="method-description">
|
557
|
-
<
|
558
|
-
calculate the an integer s >= 0 and a remainder r >= 0 such that
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
algorithm would also work for other values.
|
580
|
+
<pre>
|
581
|
+
calculate the an integer s >= 0 and a remainder r >= 0 such that
|
582
|
+
</pre>
|
583
|
+
<p>
|
584
|
+
�x�=�s**2�+�r�and�s**2�<=�x�<�(s+1)**2
|
563
585
|
</p>
|
586
|
+
<pre>
|
587
|
+
the wordwise algorithm is used, which works well for relatively
|
588
|
+
large values of x. n defines the word size to be used for the
|
589
|
+
algorithm. It is good to use half of the machine word, but the
|
590
|
+
algorithm would also work for other values.
|
591
|
+
</pre>
|
564
592
|
</div>
|
565
593
|
</div>
|
566
594
|
|
@@ -596,6 +624,11 @@ href="LongMath/Numeric.html">Numeric</a>.
|
|
596
624
|
</div>
|
597
625
|
|
598
626
|
<div class="method-description">
|
627
|
+
<p>
|
628
|
+
construct a <a href="LongMath.html#M000023">LongDecimalQuot</a> from the
|
629
|
+
given parameters 1st case: both are LongDecimals 2nd case: first is
|
630
|
+
Rational, second is scale
|
631
|
+
</p>
|
599
632
|
</div>
|
600
633
|
</div>
|
601
634
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>check_word_len (LongMath)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/longdecimal.rb, line 73</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">LongMath</span>.<span class="ruby-identifier">check_word_len</span>(<span class="ruby-identifier">word_len</span>, <span class="ruby-identifier">name</span>=<span class="ruby-value str">"word_len"</span>)
|
15
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">"#{name} must be a positive number <= 1024"</span> <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">word_len</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Fixnum</span>) <span class="ruby-operator">&&</span> <span class="ruby-identifier">word_len</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">word_len</span> <span class="ruby-operator"><=</span> <span class="ruby-value">1024</span>
|
16
|
+
<span class="ruby-identifier">word_len</span>
|
17
|
+
<span class="ruby-keyword kw">end</span></pre>
|
18
|
+
</body>
|
19
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>check_is_int (LongMath)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/longdecimal.rb, line 81</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">LongMath</span>.<span class="ruby-identifier">check_is_int</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">name</span>=<span class="ruby-value str">"x"</span>)
|
15
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">"#{name}=#{x.inspect} must be Integer"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Integer</span>
|
16
|
+
<span class="ruby-keyword kw">end</span></pre>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>check_is_ld (LongMath)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/longdecimal.rb, line 88</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">LongMath</span>.<span class="ruby-identifier">check_is_ld</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">name</span>=<span class="ruby-value str">"x"</span>)
|
15
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">"x=#{x.inspect} must be LongDecimal"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">LongDecimal</span>
|
16
|
+
<span class="ruby-keyword kw">end</span></pre>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>check_is_prec (LongMath)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/longdecimal.rb, line 96</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">LongMath</span>.<span class="ruby-identifier">check_is_prec</span>(<span class="ruby-identifier">prec</span>, <span class="ruby-identifier">name</span>=<span class="ruby-value str">"prec"</span>)
|
15
|
+
<span class="ruby-identifier">check_is_int</span>(<span class="ruby-identifier">prec</span>, <span class="ruby-value str">"prec"</span>)
|
16
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">"#{name}=#{prec.inspect} must be >= 0"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">prec</span> <span class="ruby-operator">>=</span> <span class="ruby-value">0</span>
|
17
|
+
<span class="ruby-keyword kw">end</span></pre>
|
18
|
+
</body>
|
19
|
+
</html>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>check_is_mode (LongMath)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/longdecimal.rb, line 105</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">LongMath</span>.<span class="ruby-identifier">check_is_mode</span>(<span class="ruby-identifier">mode</span>, <span class="ruby-identifier">name</span>=<span class="ruby-value str">"mode"</span>)
|
15
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">"#{name}=#{mode.inspect} must be legal rounding mode"</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">mode</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">RoundingModeClass</span>
|
16
|
+
<span class="ruby-keyword kw">end</span></pre>
|
17
|
+
</body>
|
18
|
+
</html>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>split_to_words (LongMath)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/longdecimal.rb, line 114</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">LongMath</span>.<span class="ruby-identifier">split_to_words</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">word_len</span> = <span class="ruby-value">32</span>)
|
15
|
+
<span class="ruby-identifier">check_word_len</span>(<span class="ruby-identifier">word_len</span>)
|
16
|
+
<span class="ruby-identifier">check_is_int</span>(<span class="ruby-identifier">x</span>, <span class="ruby-value str">"x"</span>)
|
17
|
+
<span class="ruby-identifier">m</span> = <span class="ruby-identifier">x</span>.<span class="ruby-identifier">abs</span>
|
18
|
+
<span class="ruby-identifier">s</span> = (<span class="ruby-identifier">x</span> <span class="ruby-operator"><=></span> <span class="ruby-value">0</span>)
|
19
|
+
<span class="ruby-identifier">bit_pattern</span> = (<span class="ruby-value">1</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">word_len</span>) <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
|
20
|
+
<span class="ruby-identifier">words</span> = []
|
21
|
+
<span class="ruby-keyword kw">while</span> (<span class="ruby-identifier">m</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">words</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>) <span class="ruby-keyword kw">do</span>
|
22
|
+
<span class="ruby-identifier">w</span> = <span class="ruby-identifier">m</span> <span class="ruby-operator">&</span> <span class="ruby-identifier">bit_pattern</span>
|
23
|
+
<span class="ruby-identifier">m</span> = <span class="ruby-identifier">m</span> <span class="ruby-operator">>></span> <span class="ruby-identifier">word_len</span>
|
24
|
+
<span class="ruby-identifier">words</span>.<span class="ruby-identifier">unshift</span>(<span class="ruby-identifier">w</span>)
|
25
|
+
<span class="ruby-keyword kw">end</span>
|
26
|
+
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">s</span> <span class="ruby-operator"><</span> <span class="ruby-value">0</span>) <span class="ruby-keyword kw">then</span>
|
27
|
+
<span class="ruby-identifier">words</span>[<span class="ruby-value">0</span>] = <span class="ruby-operator">-</span><span class="ruby-identifier">words</span>[<span class="ruby-value">0</span>]
|
28
|
+
<span class="ruby-keyword kw">end</span>
|
29
|
+
<span class="ruby-identifier">words</span>
|
30
|
+
<span class="ruby-keyword kw">end</span></pre>
|
31
|
+
</body>
|
32
|
+
</html>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>merge_from_words (LongMath)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/longdecimal.rb, line 136</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">LongMath</span>.<span class="ruby-identifier">merge_from_words</span>(<span class="ruby-identifier">words</span>, <span class="ruby-identifier">word_len</span> = <span class="ruby-value">32</span>)
|
15
|
+
<span class="ruby-identifier">check_word_len</span>(<span class="ruby-identifier">word_len</span>)
|
16
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">"words must be array of length > 0"</span> <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">words</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Array</span>) <span class="ruby-operator">&&</span> <span class="ruby-identifier">words</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
17
|
+
<span class="ruby-identifier">y</span> = <span class="ruby-value">0</span>
|
18
|
+
<span class="ruby-identifier">s</span> = (<span class="ruby-identifier">words</span>[<span class="ruby-value">0</span>] <span class="ruby-operator"><=></span> <span class="ruby-value">0</span>)
|
19
|
+
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">s</span> <span class="ruby-operator"><</span> <span class="ruby-value">0</span>) <span class="ruby-keyword kw">then</span>
|
20
|
+
<span class="ruby-identifier">words</span>[<span class="ruby-value">0</span>] = <span class="ruby-operator">-</span><span class="ruby-identifier">words</span>[<span class="ruby-value">0</span>]
|
21
|
+
<span class="ruby-keyword kw">end</span>
|
22
|
+
<span class="ruby-identifier">words</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">w</span><span class="ruby-operator">|</span>
|
23
|
+
<span class="ruby-identifier">y</span> = <span class="ruby-identifier">y</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">word_len</span>
|
24
|
+
<span class="ruby-identifier">y</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">w</span>
|
25
|
+
<span class="ruby-keyword kw">end</span>
|
26
|
+
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">s</span> <span class="ruby-operator"><</span> <span class="ruby-value">0</span>) <span class="ruby-keyword kw">then</span>
|
27
|
+
<span class="ruby-identifier">y</span> = <span class="ruby-operator">-</span><span class="ruby-identifier">y</span>
|
28
|
+
<span class="ruby-keyword kw">end</span>
|
29
|
+
<span class="ruby-identifier">y</span>
|
30
|
+
<span class="ruby-keyword kw">end</span></pre>
|
31
|
+
</body>
|
32
|
+
</html>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>sqrtb (LongMath)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/longdecimal.rb, line 160</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">LongMath</span>.<span class="ruby-identifier">sqrtb</span>(<span class="ruby-identifier">x</span>)
|
15
|
+
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">sqrtb_with_remainder</span>(<span class="ruby-identifier">x</span>)
|
16
|
+
<span class="ruby-identifier">a</span>[<span class="ruby-value">0</span>]
|
17
|
+
<span class="ruby-keyword kw">end</span></pre>
|
18
|
+
</body>
|
19
|
+
</html>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>sqrtb_with_remainder (LongMath)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/longdecimal.rb, line 171</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">LongMath</span>.<span class="ruby-identifier">sqrtb_with_remainder</span>(<span class="ruby-identifier">x</span>)
|
15
|
+
<span class="ruby-identifier">check_is_int</span>(<span class="ruby-identifier">x</span>, <span class="ruby-value str">"x"</span>)
|
16
|
+
|
17
|
+
<span class="ruby-identifier">s</span> = (<span class="ruby-identifier">x</span> <span class="ruby-operator"><=></span> <span class="ruby-value">0</span>)
|
18
|
+
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">s</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>) <span class="ruby-keyword kw">then</span>
|
19
|
+
<span class="ruby-keyword kw">return</span> [<span class="ruby-value">0</span>, <span class="ruby-value">0</span>]
|
20
|
+
<span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">s</span> <span class="ruby-operator"><</span> <span class="ruby-value">0</span>)
|
21
|
+
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">sqrtb_with_remainder</span>(<span class="ruby-operator">-</span><span class="ruby-identifier">x</span>)
|
22
|
+
<span class="ruby-keyword kw">return</span> [ <span class="ruby-constant">Complex</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">a</span>[<span class="ruby-value">0</span>]), <span class="ruby-identifier">a</span>[<span class="ruby-value">1</span>]]
|
23
|
+
<span class="ruby-keyword kw">end</span>
|
24
|
+
|
25
|
+
<span class="ruby-identifier">xwords</span> = <span class="ruby-identifier">split_to_words</span>(<span class="ruby-identifier">x</span>, <span class="ruby-value">2</span>)
|
26
|
+
<span class="ruby-identifier">xi</span> = <span class="ruby-identifier">xwords</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
|
27
|
+
<span class="ruby-identifier">yi</span> = <span class="ruby-value">1</span>
|
28
|
+
|
29
|
+
<span class="ruby-value">1</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">xwords</span>.<span class="ruby-identifier">length</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
30
|
+
<span class="ruby-identifier">xi</span> = (<span class="ruby-identifier">xi</span> <span class="ruby-operator"><<</span> <span class="ruby-value">2</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">xwords</span>[<span class="ruby-identifier">i</span>]
|
31
|
+
<span class="ruby-identifier">d0</span> = (<span class="ruby-identifier">yi</span> <span class="ruby-operator"><<</span> <span class="ruby-value">2</span>) <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
|
32
|
+
<span class="ruby-identifier">r</span> = <span class="ruby-identifier">xi</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">d0</span>
|
33
|
+
<span class="ruby-identifier">b</span> = <span class="ruby-value">0</span>
|
34
|
+
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">r</span> <span class="ruby-operator">>=</span> <span class="ruby-value">0</span>) <span class="ruby-keyword kw">then</span>
|
35
|
+
<span class="ruby-identifier">b</span> = <span class="ruby-value">1</span>
|
36
|
+
<span class="ruby-identifier">xi</span> = <span class="ruby-identifier">r</span>
|
37
|
+
<span class="ruby-keyword kw">end</span>
|
38
|
+
<span class="ruby-identifier">yi</span> = (<span class="ruby-identifier">yi</span> <span class="ruby-operator"><<</span> <span class="ruby-value">1</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">b</span>
|
39
|
+
<span class="ruby-keyword kw">end</span>
|
40
|
+
<span class="ruby-keyword kw">return</span> [<span class="ruby-identifier">yi</span>, <span class="ruby-identifier">xi</span>]
|
41
|
+
<span class="ruby-keyword kw">end</span></pre>
|
42
|
+
</body>
|
43
|
+
</html>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>sqrtw (LongMath)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/longdecimal.rb, line 210</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">LongMath</span>.<span class="ruby-identifier">sqrtw</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">n</span> = <span class="ruby-value">16</span>)
|
15
|
+
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">sqrtw_with_remainder</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">n</span>)
|
16
|
+
<span class="ruby-identifier">a</span>[<span class="ruby-value">0</span>]
|
17
|
+
<span class="ruby-keyword kw">end</span></pre>
|
18
|
+
</body>
|
19
|
+
</html>
|
@@ -0,0 +1,73 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html>
|
7
|
+
<head>
|
8
|
+
<title>sqrtw_with_remainder (LongMath)</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
11
|
+
</head>
|
12
|
+
<body class="standalone-code">
|
13
|
+
<pre><span class="ruby-comment cmt"># File lib/longdecimal.rb, line 223</span>
|
14
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-constant">LongMath</span>.<span class="ruby-identifier">sqrtw_with_remainder</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">n</span> = <span class="ruby-value">16</span>)
|
15
|
+
<span class="ruby-identifier">check_is_int</span>(<span class="ruby-identifier">x</span>, <span class="ruby-value str">"x"</span>)
|
16
|
+
<span class="ruby-identifier">check_is_int</span>(<span class="ruby-identifier">n</span>, <span class="ruby-value str">"n"</span>)
|
17
|
+
<span class="ruby-identifier">n2</span> = <span class="ruby-identifier">n</span><span class="ruby-operator"><<</span><span class="ruby-value">1</span>
|
18
|
+
<span class="ruby-identifier">n1</span> = <span class="ruby-identifier">n</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>
|
19
|
+
<span class="ruby-identifier">check_word_len</span>(<span class="ruby-identifier">n2</span>, <span class="ruby-value str">"2*n"</span>)
|
20
|
+
|
21
|
+
<span class="ruby-identifier">s</span> = (<span class="ruby-identifier">x</span> <span class="ruby-operator"><=></span> <span class="ruby-value">0</span>)
|
22
|
+
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">s</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>) <span class="ruby-keyword kw">then</span>
|
23
|
+
<span class="ruby-keyword kw">return</span> [<span class="ruby-value">0</span>, <span class="ruby-value">0</span>]
|
24
|
+
<span class="ruby-keyword kw">elsif</span> (<span class="ruby-identifier">s</span> <span class="ruby-operator"><</span> <span class="ruby-value">0</span>)
|
25
|
+
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">sqrtw_with_remainder</span>(<span class="ruby-operator">-</span><span class="ruby-identifier">x</span>)
|
26
|
+
<span class="ruby-keyword kw">return</span> [ <span class="ruby-constant">Complex</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">a</span>[<span class="ruby-value">0</span>]), <span class="ruby-identifier">a</span>[<span class="ruby-value">1</span>]]
|
27
|
+
<span class="ruby-keyword kw">end</span>
|
28
|
+
|
29
|
+
<span class="ruby-identifier">xwords</span> = <span class="ruby-identifier">split_to_words</span>(<span class="ruby-identifier">x</span>, <span class="ruby-identifier">n2</span>)
|
30
|
+
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">xwords</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>) <span class="ruby-keyword kw">then</span>
|
31
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">sqrtb_with_remainder</span>(<span class="ruby-identifier">xwords</span>[<span class="ruby-value">0</span>])
|
32
|
+
<span class="ruby-keyword kw">end</span>
|
33
|
+
|
34
|
+
<span class="ruby-comment cmt"># puts(xwords.inspect + "\n")</span>
|
35
|
+
<span class="ruby-identifier">xi</span> = (<span class="ruby-identifier">xwords</span>[<span class="ruby-value">0</span>] <span class="ruby-operator"><<</span> <span class="ruby-identifier">n2</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">xwords</span>[<span class="ruby-value">1</span>]
|
36
|
+
<span class="ruby-identifier">a</span> = <span class="ruby-identifier">sqrtb_with_remainder</span>(<span class="ruby-identifier">xi</span>)
|
37
|
+
<span class="ruby-identifier">yi</span> = <span class="ruby-identifier">a</span>[<span class="ruby-value">0</span>]
|
38
|
+
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">xwords</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator"><=</span> <span class="ruby-value">2</span>) <span class="ruby-keyword kw">then</span>
|
39
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">a</span>
|
40
|
+
<span class="ruby-keyword kw">end</span>
|
41
|
+
|
42
|
+
<span class="ruby-identifier">xi</span> <span class="ruby-operator">-=</span> <span class="ruby-identifier">yi</span><span class="ruby-operator">*</span><span class="ruby-identifier">yi</span>
|
43
|
+
<span class="ruby-value">2</span>.<span class="ruby-identifier">upto</span>(<span class="ruby-identifier">xwords</span>.<span class="ruby-identifier">length</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
|
44
|
+
<span class="ruby-identifier">xi</span> = (<span class="ruby-identifier">xi</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">n2</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">xwords</span>[<span class="ruby-identifier">i</span>]
|
45
|
+
<span class="ruby-identifier">d0</span> = (<span class="ruby-identifier">yi</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">n1</span>)
|
46
|
+
<span class="ruby-identifier">q</span> = (<span class="ruby-identifier">xi</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">d0</span>).<span class="ruby-identifier">to_i</span>
|
47
|
+
<span class="ruby-identifier">q0</span> = <span class="ruby-identifier">q</span>
|
48
|
+
<span class="ruby-identifier">j</span> = <span class="ruby-value">0</span>
|
49
|
+
<span class="ruby-identifier">was_negative</span> = <span class="ruby-keyword kw">false</span>
|
50
|
+
<span class="ruby-keyword kw">while</span> (<span class="ruby-keyword kw">true</span>) <span class="ruby-keyword kw">do</span>
|
51
|
+
<span class="ruby-identifier">d</span> = <span class="ruby-identifier">d0</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">q</span>
|
52
|
+
<span class="ruby-identifier">r</span> = <span class="ruby-identifier">xi</span> <span class="ruby-operator">-</span> (<span class="ruby-identifier">q</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">d</span>)
|
53
|
+
<span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> (<span class="ruby-value">0</span> <span class="ruby-operator"><=</span> <span class="ruby-identifier">r</span> <span class="ruby-operator">&&</span> (<span class="ruby-identifier">r</span> <span class="ruby-operator"><</span> <span class="ruby-identifier">d</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">was_negative</span>))
|
54
|
+
<span class="ruby-comment cmt"># puts("i=#{i} j=#{j} q=#{q} d0=#{d0} d=#{d} r=#{r} yi=#{yi} xi=#{xi}\n")</span>
|
55
|
+
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">r</span> <span class="ruby-operator"><</span> <span class="ruby-value">0</span>) <span class="ruby-keyword kw">then</span>
|
56
|
+
<span class="ruby-identifier">was_negative</span> = <span class="ruby-keyword kw">true</span>
|
57
|
+
<span class="ruby-identifier">q</span> = <span class="ruby-identifier">q</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>
|
58
|
+
<span class="ruby-keyword kw">else</span>
|
59
|
+
<span class="ruby-identifier">q</span> = <span class="ruby-identifier">q</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>
|
60
|
+
<span class="ruby-keyword kw">end</span>
|
61
|
+
<span class="ruby-identifier">j</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
|
62
|
+
<span class="ruby-keyword kw">if</span> (<span class="ruby-identifier">j</span> <span class="ruby-operator">></span> <span class="ruby-value">10</span>) <span class="ruby-keyword kw">then</span>
|
63
|
+
<span class="ruby-identifier">puts</span>(<span class="ruby-node">"i=#{i} j=#{j} q=#{q} q0=#{q0} d0=#{d0} d=#{d} r=#{r} yi=#{yi} xi=#{xi}\n"</span>)
|
64
|
+
<span class="ruby-keyword kw">break</span>
|
65
|
+
<span class="ruby-keyword kw">end</span>
|
66
|
+
<span class="ruby-keyword kw">end</span>
|
67
|
+
<span class="ruby-identifier">xi</span> = <span class="ruby-identifier">r</span>
|
68
|
+
<span class="ruby-identifier">yi</span> = (<span class="ruby-identifier">yi</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">n</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">q</span>
|
69
|
+
<span class="ruby-keyword kw">end</span>
|
70
|
+
<span class="ruby-keyword kw">return</span> [ <span class="ruby-identifier">yi</span>, <span class="ruby-identifier">xi</span> ]
|
71
|
+
<span class="ruby-keyword kw">end</span></pre>
|
72
|
+
</body>
|
73
|
+
</html>
|