This repository has been archived by the owner on Dec 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP6_SQUARE_ROOT_APPROXIMATION.html
585 lines (423 loc) · 30.9 KB
/
P6_SQUARE_ROOT_APPROXIMATION.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
<hr>
<p><strong>SQUARE_ROOT_APPROXIMATION</strong></p>
<hr>
<p><span style="background:#ffff00">The <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/C%2B%2B" target="_blank" rel="noopener">C++</a> program featured in this tutorial web page computes the approximate square root of a real number using an iterative algorithm.</span></p>
<p>Note that, even though the program accepts negative real numbers as input values, the square root approximation function returns negative real number values for negative real number input values. Technically, if a negative real number is that function’s input, the value returned by that function should be a positive real number multiplied by the square root of negative one (and such a return value is an <a style="background:#000000;color:#ff9000" href="https://karlinaobject.wordpress.com/numbers/" target="_blank" rel="noopener">imaginary number</a> instead of a real number).</p>
<p><em>To view hidden text inside each of the preformatted text boxes below, scroll horizontally.</em></p>
<pre>Y := square_root(X). // Y = X ^ (1/2).
(Y * Y) = X. // X = Y ^ 2.
</pre>
<hr>
<p><strong>SOFTWARE_APPLICATION_COMPONENTS</strong></p>
<hr>
<p>C++_source_file: <a style="background:#000000;color:#00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square_root_approximation.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square_root_approximation.cpp</a></p>
<p>plain-text_file: <a style="background:#000000;color:#ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square_root_approximation_output.txt" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square_root_approximation_output.txt</a></p>
<hr>
<p><strong>PROGRAM_COMPILATION_AND_EXECUTION</strong></p>
<hr>
<p>STEP_0: Copy and paste the C++ <a style="background:#000000;color:#00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square_root_approximation.cpp" target="_blank" rel="noopener">source code</a> into a new text editor document and save that document as the following file name:</p>
<pre>square_root_approximation.cpp</pre>
<p>STEP_1: Open a <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Unix" target="_blank" rel="noopener">Unix</a> command line terminal application and set the current directory to wherever the C++ program file is located on the local machine (e.g. Desktop).</p>
<pre>cd Desktop</pre>
<p>STEP_2: Compile the C++ file into machine-executable instructions (i.e. object file) and then into an executable piece of software named <strong>app</strong> using the following command:</p>
<pre>g++ square_root_approximation.cpp -o app</pre>
<p>STEP_3: If the program compilation command does not work, then use the following commands (in top-down order) to install the C/C++ compiler (which is part of the <a style="background: #ff9000;color: #000000" href="https://en.wikipedia.org/wiki/GNU_Compiler_Collection" target="_blank" rel="noopener">GNU Compiler Collection (GCC)</a>):</p>
<pre>sudo apt install build-essential</pre>
<pre>sudo apt-get install g++</pre>
<p>STEP_4: After running the <strong>g++</strong> command, run the executable file using the following command:</p>
<pre>./app</pre>
<p>STEP_5: Once the application is running, the following prompt will appear:</p>
<pre>Enter a real number (represented using only base-ten digits with an optional radix and with an optional negative sign), x, which is no larger than 100:</pre>
<p>STEP_6: Enter a value for x using the keyboard.</p>
<p>STEP_7: Statements showing program throughput and the value returned by the square root function which computes the approximate value of x raised to the power of 0.5 will be printed to the command line terminal and to the file output stream and then the following prompt will appear:</p>
<pre>Would you like to continue inputting program values? (Enter 1 if YES. Enter 0 if NO):</pre>
<p>STEP_8: Enter a value according to your preference until you decide to close the program (and save your program data to the <a style="background:#ff9000;color:#000000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square_root_approximation_output.txt" target="_blank" rel="noopener">output text file</a>).</p>
<hr>
<p><strong>PROGRAM_SOURCE_CODE</strong></p>
<hr>
<p>Note that the text inside of each of the the preformatted text boxes below appears on this web page (while rendered correctly by the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Web_browser" target="_blank" rel="noopener">web browser</a>) to be identical to the content of that preformatted text box text’s respective <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Plain_text" target="_blank" rel="noopener">plain-text</a> file or <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Source_code" target="_blank" rel="noopener">source code</a> output file (whose <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/URL" target="_blank" rel="noopener">Uniform Resource Locator</a> is displayed as the <strong style="background:#000000;color:#00ff00">green</strong> <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Hyperlink" target="_blank" rel="noopener">hyperlink</a> immediately above that preformatted text box (if that hyperlink points to a <strong>source code file</strong>) or whose Uniform Resource Locator is displayed as the <strong style="background:#000000;color:#ff9000">orange</strong> hyperlink immediately above that preformatted text box (if that hyperlink points to a <strong>plain-text file</strong>)).</p>
<p>A <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Computer" target="_blank" rel="noopener">computer</a> interprets a C++ source code as a series of programmatic instructions (i.e. <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Software" target="_blank" rel="noopener">software</a>) which govern how the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Computer_hardware" target="_blank" rel="noopener">hardware</a> of that computer behaves).</p>
<p><em>(Note that angle brackets which resemble <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/HTML" target="_blank" rel="noopener">HTML</a> tags (i.e. an “is less than” symbol (i.e. ‘<‘) followed by an “is greater than” symbol (i.e. ‘>’)) displayed on this web page have been replaced (at the source code level of this web page) with the Unicode symbols <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Less-than_sign" target="_blank" rel="noopener">U+003C</a> (which is rendered by the web browser as ‘<‘) and <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Greater-than_sign" target="_blank" rel="noopener">U+003E</a> (which is rendered by the web browser as ‘>’). That is because the <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/WordPress.com" target="_blank" rel="noopener">WordPress</a> web page editor or web browser interprets a plain-text version of an “is less than” symbol followed by an “is greater than” symbol as being an opening HTML tag (which means that the WordPress web page editor or web browser deletes or fails to display those (plain-text) inequality symbols and the content between those (plain-text) inequality symbols)).</em></p>
<p>C++_source_file: <a style="background:#000000;color:#00ff00" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square_root_approximation.cpp" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square_root_approximation.cpp</a></p>
<hr>
<pre>
/**
* file: square_root_approximation.cpp
* type: C++ (source file)
* date: 19_JUNE_2023
* author: karbytes
* license: PUBLIC_DOMAIN
*/
/* preprocessing directives */
#include <iostream> // standard input (std::cin), standard output (std::cout)
#include <fstream> // file input, file output
#define MAXIMUM_X 100 // constant which represents maximum absolute value of the program input value
#define E 0.00000001 // constant which represents the degree of accuracy of the square root approximation
/* function prototypes */
float absolute_value(float x);
long double compute_square_root_of_real_number(float x, std::ostream & output);
/**
* Return the absolute value of a real number input, x.
*/
float absolute_value(float x)
{
if (x < 0) return -1 * x;
return x;
}
/**
* Compute the approximate square root of a real number, x, using an iterative method.
*
* The square root of x is x raised to the power of 0.5 (i.e. x ^ (1/2)).
*
* Assume that x is a float type value and that output is an output stream object.
*
* This function returns a value whose data type is long double (which is a floating-point number).
*/
long double compute_square_root_of_real_number(float x, std::ostream & output)
{
int i = 0;
float original_x = x, absolute_value_of_original_x = 0.0;
long double S = 0.0, Y = 1.0;
x = absolute_value(x);
absolute_value_of_original_x = x;
x = (x > MAXIMUM_X) ? 0 : x; // If x is out of range, then set x to 0.
S = x;
output << "\n\nx = " << x << ". // real number to take the square root of";
output << "\nS = " << S << ". // variable for storing the approximate square root of x";
output << "\nY = " << Y << ". // number to add to S before dividing S by 2 for each while loop iteration, i";
while (S - Y > E)
{
S = (S + Y) / 2;
Y = absolute_value_of_original_x / S;
output << "\n\ni := " << i << ".";
output << "\nS := ((S + Y) / 2) = " << S << ".";
output << "\nY := (absolute_value_of_original_x / S) = " << Y << ".";
i += 1;
}
if (original_x < 0) return -1 * S;
return S;
}
/* program entry point */
int main()
{
// Declare a float type variable and set its initial value to zero.
float x = 0.0;
// Declare a double type variable and set its initial value to zero.
long double A = 0.0;
// Declare a variable for storing the program user's answer of whether or not to continue inputting values.
int input_additional_values = 1;
// Declare a file output stream object.
std::ofstream file;
// Set the number of digits of floating-point numbers which are printed to the command line terminal to 100 digits.
std::cout.precision(100);
// Set the number of digits of floating-point numbers which are printed to the file output stream to 100 digits.
file.precision(100);
/**
* If square_root_approximation_output.txt does not already exist in the same directory as square_root_approximation.cpp,
* create a new file named square_root_approximation_output.txt.
*
* Open the plain-text file named square_root_approximation_output.txt
* and set that file to be overwritten with program data.
*/
file.open("square_root_approximation_output.txt");
// Print an opening message to the command line terminal.
std::cout << "\n\n--------------------------------";
std::cout << "\nStart Of Program";
std::cout << "\n--------------------------------";
// Print an opening message to the file output stream.
file << "--------------------------------";
file << "\nStart Of Program";
file << "\n--------------------------------";
// Prompt the user to enter an x value as many times as the user chooses to.
while (input_additional_values != 0)
{
// Print "Enter a real number (represented using only base-ten digits with an optional radix and with an optional negative sign), x, which is no larger than {MAXIMUM_X}: " to the command line terminal.
std::cout << "\n\nEnter a real number (represented using only base-ten digits with an optional radix and with an optional negative sign), x, which is no larger than " << MAXIMUM_X << ": ";
// Scan the command line terminal for the most recent keyboard input value.
std::cin >> x;
// Print "The value which was entered for x is {x}." to the command line terminal.
std::cout << "\nThe value which was entered for x is " << x << ".";
// Print "The value which was entered for x is {x}." to the file output stream.
file << "\n\nThe value which was entered for x is " << x << ".";
// Print a horizontal line to the command line terminal.
std::cout << "\n\n--------------------------------";
// Print a horizontal line to the command line terminal.
file << "\n\n--------------------------------";
// Print "Computing the approximate square root of x:" to the command line terminal.
std::cout << "\n\nComputing the approximate square root of x:";
// Print "Computing the approximate square root of x:" to the file output stream.
file << "\n\nComputing the approximate square root of x:";
// Compute the approximate square root of x using Heron's Method, print the computational steps to the command line terminal, and store the function result in A.
A = compute_square_root_of_real_number(x, std::cout);
// Compute the approximate square root of x using Heron's Method and print the computational steps to the file output stream.
compute_square_root_of_real_number(x, file);
// Print a horizontal line to the command line terminal.
std::cout << "\n\n--------------------------------";
// Print a horizontal line to the command line terminal.
file << "\n\n--------------------------------";
// Print "A = approximate_square_root({x}) = {A}." to the command line terminal.
std::cout << "\n\nA = approximate_square_root(" << x << ") = " << A << ".";
// Print "A = approximate_square_root({x}) = {A}." to the file output stream.
file << "\n\nA = approximate_square_root(" << x << ") = " << A << ".";
// Print "(A * A) = " << {(A * A)} << ". // the approximate value of x" to the command line terminal.
std::cout << "\n\n(A * A) = " << (A * A) << ". // the approximate absolute value of x";
// Print "(A * A) = " << {(A * A)} << ". // the approximate value of x" to the file output stream.
file << "\n\n(A * A) = " << (A * A) << ". // the approximate absolute value of x";
// Ask the user whether or not to continue inputing values.
std::cout << "\n\nWould you like to continue inputing program values? (Enter 1 if YES. Enter 0 if NO): ";
// Scan the command line terminal for the most recent user input entered via keyboard to store in the variable named input_additional_values.
std::cin >> input_additional_values;
// Print a horizontal line to the command line terminal.
std::cout << "\n\n--------------------------------";
// Print a horizontal line to the command line terminal.
file << "\n\n--------------------------------";
}
// Print a closing message to the command line terminal.
std::cout << "\nEnd Of Program";
std::cout << "\n--------------------------------\n\n";
// Print a closing message to the file output stream.
file << "\nEnd Of Program";
file << "\n--------------------------------";
// Close the file output stream.
file.close();
// Exit the program.
return 0;
}
</pre>
<hr>
<p><strong>SAMPLE_PROGRAM_OUTPUT</strong></p>
<hr>
<p>The text in the preformatted text box below was generated by one use case of the C++ program featured in this <a style="background:#ff9000;color:#000000" href="https://en.wikipedia.org/wiki/Computer_programming" target="_blank" rel="noopener">computer programming</a> tutorial web page.</p>
<p>plain-text_file: <a style="background:#000000;color:#ff9000" href="https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square_root_approximation_output.txt" target="_blank" rel="noopener">https://raw.githubusercontent.com/karlinarayberinger/KARLINA_OBJECT_summer_2023_starter_pack/main/square_root_approximation_output.txt</a></p>
<hr>
<pre>
--------------------------------
Start Of Program
--------------------------------
The value which was entered for x is -25.
--------------------------------
Computing the approximate square root of x:
x = 25. // real number to take the square root of
S = 25. // variable for storing the approximate square root of x
Y = 1. // number to add to S before dividing S by 2 for each while loop iteration, i
i := 0.
S := ((S + Y) / 2) = 13.
Y := (absolute_value_of_original_x / S) = 1.923076923076923076881376839519788290999713353812694549560546875.
i := 1.
S := ((S + Y) / 2) = 7.4615384615384615384948985283841693672002293169498443603515625.
Y := (absolute_value_of_original_x / S) = 3.35051546391752577322940831461295374538167379796504974365234375.
i := 2.
S := ((S + Y) / 2) = 5.406026962727993655753733204250011112890206277370452880859375.
Y := (absolute_value_of_original_x / S) = 4.624468241161801379014717472415441079647280275821685791015625.
i := 3.
S := ((S + Y) / 2) = 5.0152476019448975173842253383327260962687432765960693359375.
Y := (absolute_value_of_original_x / S) = 4.984798754563000494459401590319203023682348430156707763671875.
i := 4.
S := ((S + Y) / 2) = 5.0000231782539490059218134643259645599755458533763885498046875.
Y := (absolute_value_of_original_x / S) = 4.99997682185349678722630084592992716352455317974090576171875.
i := 5.
S := ((S + Y) / 2) = 5.000000000053722896790897589625046748551540076732635498046875.
Y := (absolute_value_of_original_x / S) = 4.999999999946277103209102410374953251448459923267364501953125.
--------------------------------
A = approximate_square_root(-25) = -5.000000000053722896790897589625046748551540076732635498046875.
(A * A) = 25.00000000053722896790897589625046748551540076732635498046875. // the approximate absolute value of x
--------------------------------
The value which was entered for x is 100.
--------------------------------
Computing the approximate square root of x:
x = 100. // real number to take the square root of
S = 100. // variable for storing the approximate square root of x
Y = 1. // number to add to S before dividing S by 2 for each while loop iteration, i
i := 0.
S := ((S + Y) / 2) = 50.5.
Y := (absolute_value_of_original_x / S) = 1.98019801980198019799618569525279099252657033503055572509765625.
i := 1.
S := ((S + Y) / 2) = 26.24009900990099009888967263037784505286253988742828369140625.
Y := (absolute_value_of_original_x / S) = 3.81096123007263465711814964809178718496696092188358306884765625.
i := 2.
S := ((S + Y) / 2) = 15.025530119986812377895490921986265675514005124568939208984375.
Y := (absolute_value_of_original_x / S) = 6.6553392260670379662786111385486265135114081203937530517578125.
i := 3.
S := ((S + Y) / 2) = 10.84043467302692517230389146476454698131419718265533447265625.
Y := (absolute_value_of_original_x / S) = 9.22472234889428614745821022324889781884849071502685546875.
i := 4.
S := ((S + Y) / 2) = 10.032578510960605659881050844006722400081343948841094970703125.
Y := (absolute_value_of_original_x / S) = 9.96752728032478032237084786260084001696668565273284912109375.
i := 5.
S := ((S + Y) / 2) = 10.00005289564269299155963022229798298212699592113494873046875.
Y := (absolute_value_of_original_x / S) = 9.999947104637100430378493509664394878200255334377288818359375.
i := 6.
S := ((S + Y) / 2) = 10.00000000013989671053538099698698715656064450740814208984375.
Y := (absolute_value_of_original_x / S) = 9.99999999986010328946461900301301284343935549259185791015625.
--------------------------------
A = approximate_square_root(100) = 10.00000000013989671053538099698698715656064450740814208984375.
(A * A) = 100.000000002797934210707619939739743131212890148162841796875. // the approximate absolute value of x
--------------------------------
The value which was entered for x is 3.1400001049041748046875.
--------------------------------
Computing the approximate square root of x:
x = 3.1400001049041748046875. // real number to take the square root of
S = 3.1400001049041748046875. // variable for storing the approximate square root of x
Y = 1. // number to add to S before dividing S by 2 for each while loop iteration, i
i := 0.
S := ((S + Y) / 2) = 2.07000005245208740234375.
Y := (absolute_value_of_original_x / S) = 1.51690822480153237488721684744774620412499643862247467041015625.
i := 1.
S := ((S + Y) / 2) = 1.793454138626809888615483423723873102062498219311237335205078125.
Y := (absolute_value_of_original_x / S) = 1.750811485655480336811294639343117296448326669633388519287109375.
i := 2.
S := ((S + Y) / 2) = 1.77213281214114511271338903153349519925541244447231292724609375.
Y := (absolute_value_of_original_x / S) = 1.771876285677669133245167032431055531560559757053852081298828125.
i := 3.
S := ((S + Y) / 2) = 1.77200454890940712303348814060655058710835874080657958984375.
Y := (absolute_value_of_original_x / S) = 1.7720045396253132270227015343522225521155633032321929931640625.
--------------------------------
A = approximate_square_root(3.1400001049041748046875) = 1.77200454890940712303348814060655058710835874080657958984375.
(A * A) = 3.14000012135563142073695075406902788017760030925273895263671875. // the approximate absolute value of x
--------------------------------
The value which was entered for x is -16.
--------------------------------
Computing the approximate square root of x:
x = 16. // real number to take the square root of
S = 16. // variable for storing the approximate square root of x
Y = 1. // number to add to S before dividing S by 2 for each while loop iteration, i
i := 0.
S := ((S + Y) / 2) = 8.5.
Y := (absolute_value_of_original_x / S) = 1.882352941176470588241671777485208849611808545887470245361328125.
i := 1.
S := ((S + Y) / 2) = 5.191176470588235294066625780118329203105531632900238037109375.
Y := (absolute_value_of_original_x / S) = 3.082152974504249291765045626334540429525077342987060546875.
i := 2.
S := ((S + Y) / 2) = 4.1366647225462422929158357032264348163153044879436492919921875.
Y := (absolute_value_of_original_x / S) = 3.867850327050802394790451899098115973174571990966796875.
i := 3.
S := ((S + Y) / 2) = 4.00225752479852234406998423565937628154642879962921142578125.
Y := (absolute_value_of_original_x / S) = 3.99774374858735659192532363448435717145912349224090576171875.
i := 4.
S := ((S + Y) / 2) = 4.00000063669293946799765393507186672650277614593505859375.
Y := (absolute_value_of_original_x / S) = 3.99999936330716187649937654047249679933884181082248687744140625.
i := 5.
S := ((S + Y) / 2) = 4.000000000000050672140095020523631319520063698291778564453125.
Y := (absolute_value_of_original_x / S) = 3.999999999999949327859904979476368680479936301708221435546875.
--------------------------------
A = approximate_square_root(-16) = -4.000000000000050672140095020523631319520063698291778564453125.
(A * A) = 16.000000000000405377120760164189050556160509586334228515625. // the approximate absolute value of x
--------------------------------
The value which was entered for x is 0.
--------------------------------
Computing the approximate square root of x:
x = 0. // real number to take the square root of
S = 0. // variable for storing the approximate square root of x
Y = 1. // number to add to S before dividing S by 2 for each while loop iteration, i
--------------------------------
A = approximate_square_root(0) = 0.
(A * A) = 0. // the approximate absolute value of x
--------------------------------
The value which was entered for x is -1.
--------------------------------
Computing the approximate square root of x:
x = 1. // real number to take the square root of
S = 1. // variable for storing the approximate square root of x
Y = 1. // number to add to S before dividing S by 2 for each while loop iteration, i
--------------------------------
A = approximate_square_root(-1) = -1.
(A * A) = 1. // the approximate absolute value of x
--------------------------------
The value which was entered for x is 1.
--------------------------------
Computing the approximate square root of x:
x = 1. // real number to take the square root of
S = 1. // variable for storing the approximate square root of x
Y = 1. // number to add to S before dividing S by 2 for each while loop iteration, i
--------------------------------
A = approximate_square_root(1) = 1.
(A * A) = 1. // the approximate absolute value of x
--------------------------------
The value which was entered for x is -100.
--------------------------------
Computing the approximate square root of x:
x = 100. // real number to take the square root of
S = 100. // variable for storing the approximate square root of x
Y = 1. // number to add to S before dividing S by 2 for each while loop iteration, i
i := 0.
S := ((S + Y) / 2) = 50.5.
Y := (absolute_value_of_original_x / S) = 1.98019801980198019799618569525279099252657033503055572509765625.
i := 1.
S := ((S + Y) / 2) = 26.24009900990099009888967263037784505286253988742828369140625.
Y := (absolute_value_of_original_x / S) = 3.81096123007263465711814964809178718496696092188358306884765625.
i := 2.
S := ((S + Y) / 2) = 15.025530119986812377895490921986265675514005124568939208984375.
Y := (absolute_value_of_original_x / S) = 6.6553392260670379662786111385486265135114081203937530517578125.
i := 3.
S := ((S + Y) / 2) = 10.84043467302692517230389146476454698131419718265533447265625.
Y := (absolute_value_of_original_x / S) = 9.22472234889428614745821022324889781884849071502685546875.
i := 4.
S := ((S + Y) / 2) = 10.032578510960605659881050844006722400081343948841094970703125.
Y := (absolute_value_of_original_x / S) = 9.96752728032478032237084786260084001696668565273284912109375.
i := 5.
S := ((S + Y) / 2) = 10.00005289564269299155963022229798298212699592113494873046875.
Y := (absolute_value_of_original_x / S) = 9.999947104637100430378493509664394878200255334377288818359375.
i := 6.
S := ((S + Y) / 2) = 10.00000000013989671053538099698698715656064450740814208984375.
Y := (absolute_value_of_original_x / S) = 9.99999999986010328946461900301301284343935549259185791015625.
--------------------------------
A = approximate_square_root(-100) = -10.00000000013989671053538099698698715656064450740814208984375.
(A * A) = 100.000000002797934210707619939739743131212890148162841796875. // the approximate absolute value of x
--------------------------------
The value which was entered for x is 0.5.
--------------------------------
Computing the approximate square root of x:
x = 0.5. // real number to take the square root of
S = 0.5. // variable for storing the approximate square root of x
Y = 1. // number to add to S before dividing S by 2 for each while loop iteration, i
--------------------------------
A = approximate_square_root(0.5) = 0.5.
(A * A) = 0.25. // the approximate absolute value of x
--------------------------------
The value which was entered for x is 0.333000004291534423828125.
--------------------------------
Computing the approximate square root of x:
x = 0.333000004291534423828125. // real number to take the square root of
S = 0.333000004291534423828125. // variable for storing the approximate square root of x
Y = 1. // number to add to S before dividing S by 2 for each while loop iteration, i
--------------------------------
A = approximate_square_root(0.333000004291534423828125) = 0.333000004291534423828125.
(A * A) = 0.110889002858161944686798960901796817779541015625. // the approximate absolute value of x
--------------------------------
The value which was entered for x is 64.
--------------------------------
Computing the approximate square root of x:
x = 64. // real number to take the square root of
S = 64. // variable for storing the approximate square root of x
Y = 1. // number to add to S before dividing S by 2 for each while loop iteration, i
i := 0.
S := ((S + Y) / 2) = 32.5.
Y := (absolute_value_of_original_x / S) = 1.96923076923076923079591882270733549376018345355987548828125.
i := 1.
S := ((S + Y) / 2) = 17.234615384615384614530597673365264199674129486083984375.
Y := (absolute_value_of_original_x / S) = 3.713456817674626199606013887688504837569780647754669189453125.
i := 2.
S := ((S + Y) / 2) = 10.47403610114500540663462491153268274501897394657135009765625.
Y := (absolute_value_of_original_x / S) = 6.1103474708287113035913573622082139991107396781444549560546875.
i := 3.
S := ((S + Y) / 2) = 8.292191785986858355329831571367549258866347372531890869140625.
Y := (absolute_value_of_original_x / S) = 7.7181041697750993844928668607963118120096623897552490234375.
i := 4.
S := ((S + Y) / 2) = 8.00514797788097886947766834708772876183502376079559326171875.
Y := (absolute_value_of_original_x / S) = 7.994855332698205459783513671112586962408386170864105224609375.
i := 5.
S := ((S + Y) / 2) = 8.00000165528959216419691014010595608851872384548187255859375.
Y := (absolute_value_of_original_x / S) = 7.999998344710750333534654554767939771409146487712860107421875.
i := 6.
S := ((S + Y) / 2) = 8.0000000000001712484321014784427461563609540462493896484375.
Y := (absolute_value_of_original_x / S) = 7.9999999999998287515678985215572538436390459537506103515625.
--------------------------------
A = approximate_square_root(64) = 8.0000000000001712484321014784427461563609540462493896484375.
(A * A) = 64.000000000002739974913623655083938501775264739990234375. // the approximate absolute value of x
--------------------------------
End Of Program
--------------------------------
</pre>
<hr>
<p>This web page was last updated on 06_NOVEMBER_2024. The content displayed on this web page is licensed as <a style="background:#000000;color:#ff9000" href="https://karlinaobject.wordpress.com/public_domain/" target="_blank" rel="noopener">PUBLIC_DOMAIN</a> intellectual property.</p>
<hr>