28 September 2014 12:27:44 PM R4LIB_PRB C++ version Test the R4LIB library. TEST001 R4_ABS returns the absolute value of an R4. -1.25265 1.25265 4.65054 4.65054 3.63607 3.63607 1.49356 1.49356 0.322457 0.322457 -2.47105 2.47105 -0.939378 0.939378 -2.12035 2.12035 -2.64937 2.64937 2.07173 2.07173 TEST002 R4_ATAN computes the arc-tangent given Y and X; ATAN2 is the system version of this routine. X Y ATAN2(Y,X) ATAN4(Y,X) 1 0 0 0 1 1 0.785398 0.785398 0 1 1.5708 1.5708 -1 1 2.35619 2.35619 -1 0 3.14159 3.14159 -1 -1 -2.35619 3.92699 0 -1 -1.5708 4.71239 1 -1 -0.785398 5.49779 TEST003 R4_CAS evaluates the casine of a number. X R4_CAS ( X ) 0 1 0.261799 1.22474 0.523599 1.36603 0.785398 1.41421 1.0472 1.36603 1.309 1.22474 1.5708 1 1.8326 0.707107 2.0944 0.366025 2.35619 0 2.61799 -0.366026 2.87979 -0.707107 3.14159 -1 TEST004 R4_CEILING rounds a value up. -1.2 -1 -1 -1 -0.8 0 -0.6 0 -0.4 0 -0.2 0 0 0 0.2 1 0.4 1 0.6 1 0.8 1 1 1 1.2 2 TEST005 R4_DIFF computes a difference X-Y to a given number of binary places. For this test, we use 3 binary places. X Y X-Y R4_DIFF(X,Y) 1 0.0625 0.9375 0.875 1 0.125 0.875 0.875 1 0.25 0.75 0.75 1 0.5 0.5 0.5 1 0.874 0.126 0.125 1 0.876 0.124 0.125 1 0.9 0.1 0.125 1 0.95 0.05 0 1 0.99 0.00999999 0 1 1 0 0 1 1.01 -0.00999999 0 1 1.05 -0.05 0 1 1.1 -0.1 -0.1375 1 3 -2 -1.875 1 10 -9 -8.75 TEST006 R4_DIGIT extracts decimal digits. Here, we get digits of 3.14159 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 0 0 0 3 1 4 1 5 9 2 7 4 1 0 1 2 5 7 3 2 4 2 1 TEST007 R4_EPSILON produces the R4 roundoff unit. R = R4_EPSILON() = 1.19209e-07 ( 1 + R ) - 1 = 1.19209e-07 ( 1 + (R/2) ) - 1 = 0 TEST008 R4_FRACTIONAL returns the fractional part of an R4. -1.25265 0.252654 4.65054 0.650541 3.63607 0.636074 1.49356 0.493564 0.322457 0.322457 -2.47105 0.47105 -0.939378 0.939378 -2.12035 0.120346 -2.64937 0.649368 2.07173 0.0717258 TEST009 R4_HUGE returns a large R4 value; R4_HUGE = 3.40282e+38 TEST010 R4_LOG_2: computes the logarithm base 2. X R4_LOG_2 0 -1e+30 1 0 2 1 3 1.58496 9 3.16992 10 3.32193 11 3.45943 99 6.62936 101 6.65821 -1 0 -2 1 -3 1.58496 -9 3.16992 0.5 -1 0.33 -1.59946 0.25 -2 0.2 -2.32193 0.01 -6.64386 TEST011 R4_LOG_B computes the logarithm base B. X, B, R4_LOG_B 16 2 4 16 3 2.52372 16 4 2 16 5 1.72271 16 6 1.54741 16 7 1.42483 16 8 1.33333 16 16 1 16 32 0.8 16 256 0.5 TEST012 R4_MANT decomposes a value. Number to be decomposed: X = -314.159 X = -1 * 1.22718 * 2 ^ 8 TEST013 R4_MOD returns the remainder after division. R4_MOD ( X, Y ) has the same sign as X. X Y FMOD(X,Y) R4_MOD(X,Y) -5.63163 9.12635 -5.63163 -5.63163 6.59019 1.23391 0.420637 0.420637 -1.69386 -8.67763 -1.69386 -1.69386 -4.84844 -7.80086 -4.84844 -4.84844 -9.12342 2.67931 -1.08548 -1.08548 -8.76546 -1.00922 -0.691687 -0.691687 -1.97388 5.09347 -1.97388 -1.97388 5.94574 -9.96323 5.94574 5.94574 7.95008 -2.98495 1.98017 1.98017 -8.10911 -9.72766 -8.10911 -8.10911 TEST014 R4_MODP returns the remainder after division. R4_MODP ( X, Y ) is positive. X Y FMOD(X,Y) R4_MODP(X,Y) -5.63163 9.12635 -5.63163 3.49472 6.59019 1.23391 0.420637 0.420637 -1.69386 -8.67763 -1.69386 6.98377 -4.84844 -7.80086 -4.84844 2.95242 -9.12342 2.67931 -1.08548 1.59384 -8.76546 -1.00922 -0.691687 0.317534 -1.97388 5.09347 -1.97388 3.11959 5.94574 -9.96323 5.94574 5.94574 7.95008 -2.98495 1.98017 1.98017 -8.10911 -9.72766 -8.10911 1.61856 TEST015 R4_NINT produces the nearest integer. -5.63163 -6 9.12635 9 6.59019 7 1.23391 1 -1.69386 -2 -8.67763 -9 -4.84844 -5 -7.80086 -8 -9.12342 -9 2.67931 3 TEST016 R4_NORMAL_01 generates normally distributed random values. Using initial random number seed = 123456789 1.67904 -0.472768 -0.56606 -0.231124 1.21293 0.535037 1.26938 1.04954 -1.66609 -1.86523 -2.24246 0.735809 0.0396751 -1.35074 0.673068 0.00777484 -0.275127 0.37494 2.164 0.1856 TEST017 R4_PI returns the value of PI. R4_PI = 3.14159 4*atan(1) = 3.14159 TEST018 R4_POWER computes R^P R P R**P 2 -5 0.03125 2 -4 0.0625 2 -3 0.125 2 -2 0.25 2 -1 0.5 2 0 1 2 1 2 2 2 4 2 3 8 2 4 16 2 5 32 TEST019 R4_POWER_FAST computes R^P, economizing on multiplications. R P R**P Mults 2 -10 0.000976562 7 2 -9 0.00195312 7 2 -8 0.00390625 6 2 -7 0.0078125 7 2 -6 0.015625 6 2 -5 0.03125 6 2 -4 0.0625 5 2 -3 0.125 5 2 -2 0.25 4 2 -1 0.5 1 2 0 1 0 2 1 2 0 2 2 4 3 2 3 8 4 2 4 16 4 2 5 32 5 2 6 64 5 2 7 128 6 2 8 256 5 2 9 512 6 2 10 1024 6 2 11 2048 7 2 12 4096 6 2 13 8192 7 2 14 16384 7 2 15 32768 8 2 16 65536 6 2 17 131072 7 2 18 262144 7 2 19 524288 8 2 20 1.04858e+06 7 2 21 2.09715e+06 8 2 22 4.1943e+06 8 2 23 8.38861e+06 9 2 24 1.67772e+07 7 2 25 3.35544e+07 8 2 26 6.71089e+07 8 2 27 1.34218e+08 9 2 28 2.68435e+08 8 2 29 5.36871e+08 9 2 30 1.07374e+09 9 2 31 2.14748e+09 10 2 32 4.29497e+09 7 2 33 8.58993e+09 8 2 34 1.71799e+10 8 2 35 3.43597e+10 9 2 36 6.87195e+10 8 2 37 1.37439e+11 9 2 38 2.74878e+11 9 2 39 5.49756e+11 10 2 40 1.09951e+12 8 TEST020 R4_ROUND2 rounds a number to a specified number of base 2 digits. Test effect on PI: X = 3.14159 NPLACE XROUND 0 0 1 2 2 3 3 3 4 3 5 3.125 6 3.125 7 3.125 8 3.140625 9 3.140625 10 3.140625 11 3.140625 12 3.140625 13 3.14111328125 14 3.141357421875 15 3.1414794921875 16 3.14154052734375 17 3.141571044921875 18 3.141586303710938 19 3.141586303710938 20 3.141590118408203 TEST023 R4_SIGN returns the sign of an R4. R4_SIGN3 returns the three-way sign of an R4. R4 R4_SIGN(R4) R4_SIGN3(R4) -1.25 -1 -1 -0.25 -1 -1 0 1 0 0.5 1 1 9 1 1 TEST0235 R4_SWAP swaps two reals. Before swapping: X = 1 Y = 3.141590118408203 After swapping: X = 3.141590118408203 Y = 1 TEST026 R4_UNIFORM_AB produces a random real in a given range. Using range 10 <= A <= 25. I A 0 10.00199604034424 1 13.54213619232178 2 22.67935752868652 3 21.95578384399414 4 10.85564517974854 5 20.83459281921387 6 21.99637603759766 7 18.11050415039062 8 18.22058486938477 9 23.34668731689453 TEST027 R4_UNIFORM_01 produces a sequence of random values. Using random seed 123456789. SEED R4_UNIFORM_01(SEED) 123456789 0.218418300151825 469049721 0.9563176035881042 2053676357 0.8295092582702637 1781357515 0.5616954565048218 1206231778 0.4153070747852325 891865166 0.06611873209476471 141988902 0.2575778067111969 553144097 0.109956793487072 236130416 0.04382899776101112 94122056 0.6339657306671143 Verify that the sequence can be restarted. Set the seed back to its original value, and see that we generate the same sequence. SEED R4_UNIFORM_01(SEED) 123456789 0.218418300151825 469049721 0.9563176035881042 2053676357 0.8295092582702637 1781357515 0.5616954565048218 1206231778 0.4153070747852325 891865166 0.06611873209476471 141988902 0.2575778067111969 553144097 0.109956793487072 236130416 0.04382899776101112 94122056 0.6339657306671143 TEST028 R4_UNIFORM_01 samples a uniform random distribution in [0,1]. distributed random numbers. Using initial random number seed = 123456789 First few values: 0 0.218418300151825 1 0.9563176035881042 2 0.8295092582702637 3 0.5616954565048218 4 0.4153070747852325 5 0.06611873209476471 6 0.2575778067111969 7 0.109956793487072 8 0.04382899776101112 9 0.6339657306671143 Number of samples was 1000 Minimum value was 0.001838371157646179 Maximum value was 0.997908353805542 Average value was 0.5030398964881897 Variance was 0.08233196288347244 TEST012555 R4VEC_INDICATOR0_NEW returns an indicator vector. Indicator0 vector: 0: 0 1: 1 2: 2 3: 3 4: 4 5: 5 6: 6 7: 7 8: 8 9: 9 R4LIB_PRB Normal end of execution. 28 September 2014 12:27:44 PM