def dvec_complementx_test ( ): #*****************************************************************************80 # ## DVEC_COMPLEMENTX_TEST tests DVEC_COMPLEMENTX; # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 May 2015 # # Author: # # John Burkardt # from dvec_to_i4 import dvec_to_i4 from dvec_print import dvec_print from i4_to_dvec import i4_to_dvec from i4_uniform_ab import i4_uniform_ab n = 10 seed = 123456789 test_num = 5 print '' print 'DVEC_COMPLEMENTX_TEST' print ' DVEC_COMPLEMENTX returns the ten''s complement' print ' of a (signed) decimal vector;' for test in range ( 0, test_num ): i, seed = i4_uniform_ab ( -100, 100, seed ) dvec1 = i4_to_dvec ( i, n ) dvec2 = dvec_complementx ( n, dvec1 ) j = dvec_to_i4 ( n, dvec2 ) print '' print ' I = %8d' % ( i ) print ' J = %8d' % ( j ) dvec_print ( n, dvec1, '' ) dvec_print ( n, dvec2, '' ) # # Terminate. # print '' print 'DVEC_COMPLEMENTX_TEST:' print ' Normal end of execution.' return
def dvec_to_i4_test ( ): #*****************************************************************************80 # ## DVEC_TO_I4_TEST tests DVEC_TO_I4 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 May 2015 # # Author: # # John Burkardt # from i4_to_dvec import i4_to_dvec from i4_uniform_ab import i4_uniform_ab print '' print 'DVEC_TO_I4_TEST' print ' DVEC_TO_I4 converts a DVEC to an I4.' print '' print ' I4 => DVEC => I4' print '' seed = 123456789 i1, seed = i4_uniform_ab ( -10000, 10000, seed ) n = 6 dvec = i4_to_dvec ( i1, n ) i2 = dvec_to_i4 ( n, dvec ) print ' %6d ' % ( i1 ), for i in range ( n - 1, -1, -1 ): print '%2d' % ( dvec[i] ), print ' %6d' % ( i2 ) # # Terminate. # print '' print 'DVEC_TO_I4_TEST:' print ' Normal end of execution.' return
def dvec_to_i4_test(): #*****************************************************************************80 # ## DVEC_TO_I4_TEST tests DVEC_TO_I4 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 May 2015 # # Author: # # John Burkardt # from i4_to_dvec import i4_to_dvec from i4_uniform_ab import i4_uniform_ab print '' print 'DVEC_TO_I4_TEST' print ' DVEC_TO_I4 converts a DVEC to an I4.' print '' print ' I4 => DVEC => I4' print '' seed = 123456789 i1, seed = i4_uniform_ab(-10000, 10000, seed) n = 6 dvec = i4_to_dvec(i1, n) i2 = dvec_to_i4(n, dvec) print ' %6d ' % (i1), for i in range(n - 1, -1, -1): print '%2d' % (dvec[i]), print ' %6d' % (i2) # # Terminate. # print '' print 'DVEC_TO_I4_TEST:' print ' Normal end of execution.' return
def dvec_add_test ( ): #*****************************************************************************80 # ## DVEC_ADD_TEST tests DVEC_ADD. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 28 May 2015 # # Author: # # John Burkardt # from dvec_to_i4 import dvec_to_i4 from i4_to_dvec import i4_to_dvec from i4_uniform_ab import i4_uniform_ab n = 10 seed = 123456789 test_num = 10 print '' print 'DVEC_ADD_TEST' print ' DVEC_ADD adds decimal vectors representing integers' print '' print ' I J K = I + J' print '' for test in range ( 0, test_num ): i, seed = i4_uniform_ab ( -100, 100, seed ) j, seed = i4_uniform_ab ( -100, 100, seed ) print '' print ' %8d %8d' % ( i, j ) k = i + j print ' Directly: %8d' % ( k ) dvec1 = i4_to_dvec ( i, n ) dvec2 = i4_to_dvec ( j, n ) dvec3 = dvec_add ( n, dvec1, dvec2 ) k = dvec_to_i4 ( n, dvec3 ) print ' DVEC_ADD %8d' % ( k ) # # Terminate. # print '' print 'DVEC_ADD_TEST' print ' Normal end of execution.' return
def dvec_mul_test ( ): #*****************************************************************************80 # ## DVEC_MUL_TEST tests DVEC_MUL; # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 29 May 2015 # # Author: # # John Burkardt # from dvec_to_i4 import dvec_to_i4 from i4_to_dvec import i4_to_dvec from i4_uniform_ab import i4_uniform_ab n = 10 seed = 123456789 test_num = 10 test2_num = 2 print '' print 'DVEC_MUL_TEST' print ' DVEC_MUL multiplies decimal vectors' print ' representing integers;' for test2 in range ( 0, test2_num ): if ( test2 == 0 ): n2 = n elif ( test2 == 1 ): n2 = 6 print '' print ' NOW REPEAT THE TEST...' print '' print ' but use too few digits to represent big products.' print ' This corresponds to an "overflow".' print ' The result here should get the final decimal' print ' digits correctly, though.' print '' print ' I J K = I * J' for test in range ( 0, test_num ): i, seed = i4_uniform_ab ( -1000, 1000, seed ) j, seed = i4_uniform_ab ( -1000, 1000, seed ) print '' print ' %8d %8d' % ( i, j ) k = i * j print ' Directly: %8d' % ( k ) dvec1 = i4_to_dvec ( i, n2 ) dvec2 = i4_to_dvec ( j, n2 ) dvec3 = dvec_mul ( n2, dvec1, dvec2 ) k = dvec_to_i4 ( n2, dvec3 ) print ' DVEC_MUL %8d\n' % ( k ) # # Terminate. # print '' print 'DVEC_MUL_TEST' print ' Normal end of execution.' return
def dvec_sub_test(): #*****************************************************************************80 # ## DVEC_SUB_TEST tests DVEC_SUB; # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 29 May 2015 # # Author: # # John Burkardt # from dvec_to_i4 import dvec_to_i4 from i4_to_dvec import i4_to_dvec from i4_uniform_ab import i4_uniform_ab n = 10 seed = 123456789 test_num = 10 print '' print 'DVEC_SUB_TEST' print ' DVEC_SUB subtracts decimal vectors representing integers;' print '' print ' I J L = I - J' for test in range(0, test_num): i, seed = i4_uniform_ab(-100, 100, seed) j, seed = i4_uniform_ab(-100, 100, seed) print '' print ' %8d %8d' % (i, j) l = i - j print ' Directly: %8d' % (l) dvec1 = i4_to_dvec(i, n) dvec2 = i4_to_dvec(j, n) dvec4 = dvec_sub(n, dvec1, dvec2) l = dvec_to_i4(n, dvec4) print ' DVEC_SUB %8d' % (l) # # Terminate. # print '' print 'DVEC_SUB_TEST' print ' Normal end of execution.' return
def dvec_mul_test(): #*****************************************************************************80 # ## DVEC_MUL_TEST tests DVEC_MUL; # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 29 May 2015 # # Author: # # John Burkardt # from dvec_to_i4 import dvec_to_i4 from i4_to_dvec import i4_to_dvec from i4_uniform_ab import i4_uniform_ab n = 10 seed = 123456789 test_num = 10 test2_num = 2 print '' print 'DVEC_MUL_TEST' print ' DVEC_MUL multiplies decimal vectors' print ' representing integers;' for test2 in range(0, test2_num): if (test2 == 0): n2 = n elif (test2 == 1): n2 = 6 print '' print ' NOW REPEAT THE TEST...' print '' print ' but use too few digits to represent big products.' print ' This corresponds to an "overflow".' print ' The result here should get the final decimal' print ' digits correctly, though.' print '' print ' I J K = I * J' for test in range(0, test_num): i, seed = i4_uniform_ab(-1000, 1000, seed) j, seed = i4_uniform_ab(-1000, 1000, seed) print '' print ' %8d %8d' % (i, j) k = i * j print ' Directly: %8d' % (k) dvec1 = i4_to_dvec(i, n2) dvec2 = i4_to_dvec(j, n2) dvec3 = dvec_mul(n2, dvec1, dvec2) k = dvec_to_i4(n2, dvec3) print ' DVEC_MUL %8d\n' % (k) # # Terminate. # print '' print 'DVEC_MUL_TEST' print ' Normal end of execution.' return