# include # include # include # include using namespace std; # include "r8lib.hpp" int main ( ); void i4int_to_r8int_test ( ); void perm0_check_test ( ); void perm0_uniform_test ( ); void perm1_check_test ( ); void perm1_uniform_test ( ); void r8_abs_test ( ); void r8_acos_test ( ); void r8_acosh_test ( ); void r8_asinh_test ( ); void r8_atan_test ( ); void r8_atanh_test ( ); void r8_big_test ( ); void r8_cas_test ( ); void r8_ceiling_test ( ); void r8_choose_test ( ); void r8_cosd_test ( ); void r8_cotd_test ( ); void r8_cscd_test ( ); void r8_cube_root_test ( ); void r8_diff_test ( ); void r8_digit_test ( ); void r8_e_test ( ); void r8_epsilon_test ( ); void r8_epsilon_compute_test ( ); void r8_factorial_test ( ); void r8_factorial2_test ( ); void r8_fall_test ( ); void r8_fractional_test ( ); void r8_gamma_test ( ); void r8_gamma_log_test ( ); void r8_huge_test ( ); void r8_log_2_test ( ); void r8_log_b_test ( ); void r8_mant_test ( ); void r8_max_test ( ); void r8_min_test ( ); void r8_mod_test ( ); void r8_modp_test ( ); void r8_mop_test ( ); void r8_nint_test ( ); void r8_normal_01_test ( ); void r8_pi_test ( ); void r8_power_test ( ); void r8_power_fast_test ( ); void r8_rise_test ( ); void r8_round2_test ( ); void r8_roundb_test ( ); void r8_roundx_test ( ); void r8_secd_test ( ); void r8_sign_test ( ); void r8_sign3_test ( ); void r8_sind_test ( ); void r8_swap_test ( ); void r8_swap3_test ( ); void r8_tand_test ( ); void r8_to_i4_test ( ); void r8_to_r8_discrete_test ( ); void r8_uniform_01_test ( ); void r8_uniform_ab_test ( ); void r8_walsh_1d_test ( ); void r8_wrap_test ( ); void r82col_print_part_test ( ); void r82poly2_type_test ( ); void r82row_order_type_test( ); void r82row_part_quick_a_test ( ); void r82row_print_part_test ( ); void r82row_sort_heap_index_a_test ( ); void r82row_sort_quick_a_test ( ); void r83col_print_part_test ( ); void r83row_print_part_test ( ); void r8block_expand_linear_test ( ); void r8block_new_test ( ); void r8block_print_test ( ); void r8cmat_to_r8mat_new_test ( ); void r8col_find_test ( ); void r8col_insert_test ( ); void r8col_sort_heap_a_test ( ); void r8col_sort_heap_index_a_test ( ); void r8col_sort_quick_a_test ( ); void r8col_sorted_tol_unique_test ( ); void r8col_sorted_unique_count_test ( ); void r8col_sorted_tol_undex_test ( ); void r8col_max_test ( ); void r8col_mean_test ( ); void r8col_min_test ( ); void r8col_permute_test ( ); void r8col_sortr_a_test ( ); void r8col_sum_test ( ); void r8col_swap_test ( ); void r8col_to_r8vec_test ( ); void r8col_tol_undex_test ( ); void r8col_undex_test ( ); void r8col_unique_count_test ( ); void r8col_variance_test ( ); void r8int_to_i4int_test ( ); void r8mat_cholesky_inverse_test ( ); void r8mat_cholesky_solve_test ( ); void r8mat_cholesky_solve_upper_test ( ); void r8mat_det_2d_test ( ); void r8mat_det_3d_test ( ); void r8mat_det_4d_test ( ); void r8mat_det_5d_test ( ); void r8mat_expand_linear_test ( ); void r8mat_expand_linear2_test ( ); void r8mat_fs_new_test ( ); void r8mat_fss_new_test ( ); void r8mat_givens_post_test ( ); void r8mat_givens_pre_test ( ); void r8mat_hess_test ( ); double r8mat_hess_f ( int n, double x[] ); double *r8mat_hess_exact ( int n, double x[] ); void r8mat_house_axh_test ( ); void r8mat_house_form_test ( ); void r8mat_house_post_test ( ); void r8mat_house_pre_test ( ); void r8mat_indicator_new_test ( ); void r8mat_inverse_2d_test ( ); void r8mat_inverse_3d_test ( ); void r8mat_inverse_4d_test ( ); void r8mat_jac_test ( ); double *r8mat_jac_f ( int m, int n, double x[] ); double *r8mat_jac_exact ( int m, int n, double x[] ); void r8mat_kronecker_test ( ); void r8mat_l_inverse_test ( ); void r8mat_l_print_test ( ); void r8mat_l1_inverse_test ( ); void r8mat_lu_test ( ); void r8mat_max_test ( ); void r8mat_max_index_test ( ); void r8mat_maxcol_minrow_test ( ); void r8mat_maxrow_mincol_test ( ); void r8mat_min_test ( ); void r8mat_min_index_test ( ); void r8mat_mincol_maxrow_test ( ); void r8mat_minrow_maxcol_test ( ); void r8mat_mm_test ( ); void r8mat_mm_new_test ( ); void r8mat_mv_new_test ( ); void r8mat_mv_test ( ); void r8mat_mtv_new_test ( ); void r8mat_mtv_test ( ); void r8mat_nint_test ( ); void r8mat_nonzeros_test ( ); void r8mat_norm_fro_test ( ); void r8mat_norm_l1_test ( ); void r8mat_nullspace_test ( ); void r8mat_nullspace_size_test ( ); void r8mat_orth_uniform_new_test ( ); void r8mat_plot_test ( ); void r8mat_power_method_test ( ); void r8mat_print_test ( ); void r8mat_print_some_test ( ); void r8mat_ref_test ( ); void r8mat_rref_test ( ); void r8mat_solve_test ( ); void r8mat_solve_2d_test ( ); void r8mat_solve_3d_test ( ); void r8mat_solve2_test ( ); void r8mat_sub_new_test ( ); void r8mat_symm_jacobi_test ( ); void r8mat_to_r8cmat_new_test ( ); void r8mat_to_r8plu_test ( ); void r8mat_to_r8rmat_test ( ); void r8mat_trace_test ( ); void r8mat_transpose_new_test ( ); void r8mat_transpose_print_test ( ); void r8mat_u_inverse_test ( ); void r8mat_u1_inverse_test ( ); void r8mat_uniform_ab_new_test ( ); void r8plu_det_test ( ); void r8plu_inverse_test ( ); void r8plu_mul_test ( ); void r8plu_sol_test ( ); void r8plu_to_r8mat_test ( ); void r8poly_degree_test ( ); void r8poly_deriv_test ( ); void r8poly_lagrange_coef_test ( ); void r8poly_lagrange_0_test ( ); void r8poly_lagrange_1_test ( ); void r8poly_lagrange_2_test ( ); void r8poly_lagrange_factor_test ( ); void r8poly_lagrange_val_test ( ); void r8poly_print_test ( ); void r8poly_value_horner_test ( ); void r8poly_values_horner_test ( ); void r8poly2_ex_test ( ); void r8poly2_ex2_test ( ); void r8poly2_val_test ( ); void r8poly2_val_f ( double x, double *y, double *yp, double *ypp ); void r8poly2_val2_test ( ); void r8rmat_new_test ( ); void r8rmat_to_r8mat_test ( ); void r8row_max_test ( ); void r8row_mean_test ( ); void r8row_min_test ( ); void r8row_sum_test ( ); void r8row_swap_test ( ); void r8row_to_r8vec_test ( ); void r8row_variance_test ( ); void r8r8vec_index_insert_unique_test ( ); void r8r8r8vec_index_insert_unique_test ( ); void r8slmat_print_test ( ); void r8vec_amax_test ( ); void r8vec_amin_test ( ); void r8vec_bracket_test ( ); void r8vec_bracket2_test ( ); void r8vec_bracket3_test ( ); void r8vec_bracket5_test ( ); void r8vec_chebyspace_new_test ( ); void r8vec_concatenate_new_test ( ); void r8vec_convolution_test ( ); void r8vec_convolution_circ_test ( ); void r8vec_dif_test ( ); double r8vec_dif_f ( double x ); void r8vec_direct_product_test ( ); void r8vec_direct_product2_test ( ); void r8vec_even_test ( ); void r8vec_even2_test ( ); void r8vec_expand_linear_test ( ); void r8vec_frac_test ( ); void r8vec_histogram_test ( ); void r8vec_house_column_test ( ); void r8vec_index_delete_all_test ( ); void r8vec_index_delete_dupes_test ( ); void r8vec_index_delete_one_test ( ); void r8vec_index_insert_test ( ); void r8vec_index_insert_unique_test ( ); void r8vec_index_order_test ( ); void r8vec_index_search_test ( ); void r8vec_index_sorted_range_test ( ); void r8vec_indexed_heap_d_test ( ); void r8vec_indexed_heap_d_extract_test ( ); void r8vec_indexed_heap_d_insert_test ( ); void r8vec_indexed_heap_d_max_test ( ); void r8vec_indicator0_new_test ( ); void r8vec_legendre_test ( ); void r8vec_linspace_new_test ( ); void r8vec_max_test ( ); void r8vec_max_index_test ( ); void r8vec_mean_test ( ); void r8vec_median_test ( ); void r8vec_midspace_new_test ( ); void r8vec_min_test ( ); void r8vec_min_index_test ( ); void r8vec_nint_test ( ); void r8vec_norm_l0_test ( ); void r8vec_norm_l1_test ( ); void r8vec_norm_l2_test ( ); void r8vec_norm_li_test ( ); void r8vec_normal_01_test ( ); void r8vec_normalize_l1_test ( ); void r8vec_order_type_test ( ); void r8vec_permute_test ( ); void r8vec_permute_uniform_test ( ); void r8vec_polarize_test ( ); void r8vec_print_test ( ); void r8vec_rotate_test ( ); void r8vec_reverse_test ( ); void r8vec_search_binary_a_test ( ); void r8vec_sort_bubble_a_test ( ); void r8vec_sort_heap_a_test ( ); void r8vec_sort_heap_d_test ( ); void r8vec_sort_heap_index_a_new_test ( ); void r8vec_sort_heap_index_d_new_test ( ); void r8vec_sort_heap_mask_a_test ( ); void r8vec_sort_insert_a_test ( ); void r8vec_sort_insert_index_a_test ( ); void r8vec_sort_quick_a_test ( ); void r8vec_sorted_merge_a_test ( ); void r8vec_sorted_nearest_test ( ); void r8vec_sorted_range_test ( ); void r8vec_sorted_split_test ( ); void r8vec_sorted_undex_test ( ); void r8vec_sorted_unique_test ( ); void r8vec_sorted_unique_count_test ( ); void r8vec_sorted_unique_hist_test ( ); void r8vec_split_test ( ); void r8vec_transpose_print_test ( ); void r8vec_undex_test ( ); void r8vec_uniform_01_new_test ( ); void r8vec_uniform_ab_new_test ( ); void r8vec_variance_test ( ); void r8vec2_sort_a_test ( ); void r8vec2_sort_d_test ( ); void r8vec2_sort_heap_index_a_test ( ); void r8vec2_sorted_unique_test ( ); void r8vec2_sorted_unique_index_test ( ); void r8vec2_sum_max_index_test ( ); void roots_to_r8poly_test ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // MAIN is the main program for R8LIB_PRB. // // Discussion: // // R8LIB_PRB tests the R8LIB library. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 23 May 2015 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "R8LIB_PRB\n"; cout << " C++ version\n"; cout << " Test the R8LIB library.\n"; i4int_to_r8int_test ( ); perm0_check_test ( ); perm0_uniform_test ( ); perm1_check_test ( ); perm1_uniform_test ( ); r8_abs_test ( ); r8_acos_test ( ); r8_acosh_test ( ); r8_asinh_test ( ); r8_atan_test ( ); r8_atanh_test ( ); r8_big_test ( ); r8_cas_test ( ); r8_ceiling_test ( ); r8_choose_test ( ); r8_cosd_test ( ); r8_cotd_test ( ); r8_cscd_test ( ); r8_cube_root_test ( ); r8_diff_test ( ); r8_digit_test ( ); r8_e_test ( ); r8_epsilon_test ( ); r8_epsilon_compute_test ( ); r8_factorial_test ( ); r8_factorial2_test ( ); r8_fall_test ( ); r8_fractional_test ( ); r8_gamma_test ( ); r8_gamma_log_test ( ); r8_huge_test ( ); r8_log_2_test ( ); r8_log_b_test ( ); r8_mant_test ( ); r8_max_test ( ); r8_min_test ( ); r8_mod_test ( ); r8_modp_test ( ); r8_mop_test ( ); r8_nint_test ( ); r8_normal_01_test ( ); r8_pi_test ( ); r8_power_test ( ); r8_power_fast_test ( ); r8_rise_test ( ); r8_round2_test ( ); r8_roundb_test ( ); r8_roundx_test ( ); r8_secd_test ( ); r8_sign_test ( ); r8_sign3_test ( ); r8_sind_test ( ); r8_swap_test ( ); r8_swap3_test ( ); r8_tand_test ( ); r8_to_i4_test ( ); r8_to_r8_discrete_test ( ); r8_uniform_01_test ( ); r8_uniform_ab_test ( ); r8_walsh_1d_test ( ); r8_wrap_test ( ); r82col_print_part_test ( ); r82poly2_type_test ( ); r82row_order_type_test ( ); r82row_part_quick_a_test ( ); r82row_print_part_test ( ); r82row_sort_heap_index_a_test ( ); r82row_sort_quick_a_test ( ); r83col_print_part_test ( ); r83row_print_part_test ( ); r8block_expand_linear_test ( ); r8block_new_test ( ); r8block_print_test ( ); r8cmat_to_r8mat_new_test ( ); r8col_find_test ( ); r8col_insert_test ( ); r8col_sort_heap_a_test ( ); r8col_sort_heap_index_a_test ( ); r8col_sort_quick_a_test ( ); r8col_sorted_tol_unique_test ( ); r8col_sorted_unique_count_test ( ); r8col_sorted_tol_undex_test ( ); r8col_max_test ( ); r8col_mean_test ( ); r8col_min_test ( ); r8col_permute_test ( ); r8col_sortr_a_test ( ); r8col_sum_test ( ); r8col_swap_test ( ); r8col_to_r8vec_test ( ); r8col_tol_undex_test ( ); r8col_undex_test ( ); r8col_unique_count_test ( ); r8col_variance_test ( ); r8int_to_i4int_test ( ); r8mat_cholesky_inverse_test ( ); r8mat_cholesky_solve_test ( ); r8mat_cholesky_solve_upper_test ( ); r8mat_det_2d_test ( ); r8mat_det_3d_test ( ); r8mat_det_4d_test ( ); r8mat_det_5d_test ( ); r8mat_expand_linear_test ( ); r8mat_expand_linear2_test ( ); r8mat_fs_new_test ( ); r8mat_fss_new_test ( ); r8mat_givens_post_test ( ); r8mat_givens_pre_test ( ); r8mat_hess_test ( ); r8mat_house_axh_test ( ); r8mat_house_form_test ( ); r8mat_house_post_test ( ); r8mat_house_pre_test ( ); r8mat_indicator_new_test ( ); r8mat_inverse_2d_test ( ); r8mat_inverse_3d_test ( ); r8mat_inverse_4d_test ( ); r8mat_jac_test ( ); r8mat_kronecker_test ( ); r8mat_l_inverse_test ( ); r8mat_l_print_test ( ); r8mat_l1_inverse_test ( ); r8mat_lu_test ( ); r8mat_max_test ( ); r8mat_max_index_test ( ); r8mat_maxcol_minrow_test ( ); r8mat_maxrow_mincol_test ( ); r8mat_min_test ( ); r8mat_min_index_test ( ); r8mat_mincol_maxrow_test ( ); r8mat_minrow_maxcol_test ( ); r8mat_mm_test ( ); r8mat_mm_new_test ( ); r8mat_mv_new_test ( ); r8mat_mv_test ( ); r8mat_mtv_new_test ( ); r8mat_mtv_test ( ); r8mat_nint_test ( ); r8mat_nonzeros_test ( ); r8mat_norm_fro_test ( ); r8mat_norm_l1_test ( ); r8mat_nullspace_test ( ); r8mat_nullspace_size_test ( ); r8mat_orth_uniform_new_test ( ); r8mat_plot_test ( ); r8mat_power_method_test ( ); r8mat_print_test ( ); r8mat_print_some_test ( ); r8mat_ref_test ( ); r8mat_rref_test ( ); r8mat_solve_test ( ); r8mat_solve_2d_test ( ); r8mat_solve_3d_test ( ); r8mat_solve2_test ( ); r8mat_sub_new_test ( ); r8mat_symm_jacobi_test ( ); r8mat_to_r8cmat_new_test ( ); r8mat_to_r8plu_test ( ); r8mat_to_r8rmat_test ( ); r8mat_trace_test ( ); r8mat_transpose_new_test ( ); r8mat_transpose_print_test ( ); r8mat_u_inverse_test ( ); r8mat_u1_inverse_test ( ); r8mat_uniform_ab_new_test ( ); r8plu_det_test ( ); r8plu_inverse_test ( ); r8plu_mul_test ( ); r8plu_sol_test ( ); r8plu_to_r8mat_test ( ); r8poly_degree_test ( ); r8poly_deriv_test ( ); r8poly_lagrange_coef_test ( ); r8poly_lagrange_0_test ( ); r8poly_lagrange_1_test ( ); r8poly_lagrange_2_test ( ); r8poly_lagrange_factor_test ( ); r8poly_lagrange_val_test ( ); r8poly_print_test ( ); r8poly_value_horner_test ( ); r8poly_values_horner_test ( ); r8poly2_ex_test ( ); r8poly2_ex2_test ( ); r8poly2_val_test ( ); r8poly2_val2_test ( ); r8r8vec_index_insert_unique_test ( ); r8r8r8vec_index_insert_unique_test ( ); r8rmat_new_test ( ); r8rmat_to_r8mat_test ( ); r8row_max_test ( ); r8row_mean_test ( ); r8row_min_test ( ); r8row_sum_test ( ); r8row_swap_test ( ); r8row_to_r8vec_test ( ); r8row_variance_test ( ); r8slmat_print_test ( ); r8vec_amax_test ( ); r8vec_amin_test ( ); r8vec_bracket_test ( ); r8vec_bracket2_test ( ); r8vec_bracket3_test ( ); r8vec_bracket5_test ( ); r8vec_chebyspace_new_test ( ); r8vec_concatenate_new_test ( ); r8vec_convolution_test ( ); r8vec_convolution_circ_test ( ); r8vec_dif_test ( ); r8vec_direct_product_test ( ); r8vec_direct_product2_test ( ); r8vec_even_test ( ); r8vec_even2_test ( ); r8vec_expand_linear_test ( ); r8vec_frac_test ( ); r8vec_histogram_test ( ); r8vec_house_column_test ( ); r8vec_index_delete_all_test ( ); r8vec_index_delete_dupes_test ( ); r8vec_index_delete_one_test ( ); r8vec_index_insert_test ( ); r8vec_index_insert_unique_test ( ); r8vec_index_order_test ( ); r8vec_index_search_test ( ); r8vec_index_sorted_range_test ( ); r8vec_indexed_heap_d_test ( ); r8vec_indexed_heap_d_extract_test ( ); r8vec_indexed_heap_d_insert_test ( ); r8vec_indexed_heap_d_max_test ( ); r8vec_indicator0_new_test ( ); r8vec_legendre_test ( ); r8vec_linspace_new_test ( ); r8vec_max_test ( ); r8vec_max_index_test ( ); r8vec_mean_test ( ); r8vec_median_test ( ); r8vec_midspace_new_test ( ); r8vec_min_test ( ); r8vec_min_index_test ( ); r8vec_nint_test ( ); r8vec_norm_l0_test ( ); r8vec_norm_l1_test ( ); r8vec_norm_l2_test ( ); r8vec_norm_li_test ( ); r8vec_normal_01_test ( ); r8vec_normalize_l1_test ( ); r8vec_order_type_test ( ); r8vec_permute_test ( ); r8vec_permute_uniform_test ( ); r8vec_polarize_test ( ); r8vec_print_test ( ); r8vec_rotate_test ( ); r8vec_reverse_test ( ); r8vec_search_binary_a_test ( ); r8vec_sort_bubble_a_test ( ); r8vec_sort_heap_a_test ( ); r8vec_sort_heap_d_test ( ); r8vec_sort_heap_index_a_new_test ( ); r8vec_sort_heap_index_d_new_test ( ); r8vec_sort_heap_mask_a_test ( ); r8vec_sort_insert_a_test ( ); r8vec_sort_insert_index_a_test ( ); r8vec_sort_quick_a_test ( ); r8vec_sorted_merge_a_test ( ); r8vec_sorted_nearest_test ( ); r8vec_sorted_range_test ( ); r8vec_sorted_split_test ( ); r8vec_sorted_undex_test ( ); r8vec_sorted_unique_test ( ); r8vec_sorted_unique_count_test ( ); r8vec_sorted_unique_hist_test ( ); r8vec_split_test ( ); r8vec_transpose_print_test ( ); r8vec_undex_test ( ); r8vec_uniform_01_new_test ( ); r8vec_uniform_ab_new_test ( ); r8vec_variance_test ( ); r8vec2_sort_a_test ( ); r8vec2_sort_d_test ( ); r8vec2_sort_heap_index_a_test ( ); r8vec2_sorted_unique_test ( ); r8vec2_sorted_unique_index_test ( ); r8vec2_sum_max_index_test ( ); roots_to_r8poly_test ( ); // // Terminate. // cout << "\n"; cout << "R8LIB_PRB\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void i4int_to_r8int_test ( ) //****************************************************************************80 // // Purpose: // // I4INT_TO_R8INT_TEST tests I4INT_TO_R8INT; // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 18 October 2005 // // Author: // // John Burkardt // { int i; int ihi = 11; int ilo = 1; int ir; double r; double r2; double rhi = 200.0; double rhi2; double rlo = 100.0; double rlo2; int seed; int test; int test_num = 10; cout << "\n"; cout << "I4INT_TO_R8INT_TEST\n"; cout << " For data in an interval,\n"; cout << " I4INT_TO_R8INT converts an integer to a real;\n"; cout << "\n"; cout << " Integer interval: [" << ilo << ", " << ihi << "]\n"; cout << " Real interval: [" << rlo << ", " << rhi << "]\n"; cout << "\n"; cout << " R I(R) R(I(R))\n"; cout << "\n"; seed = 123456789; rlo2 = rlo - 15.0; rhi2 = rhi + 15.0; for ( test = 1; test <= test_num; test++ ) { r = r8_uniform_ab ( rlo2, rhi2, seed ); ir = r8int_to_i4int ( rlo, rhi, r, ilo, ihi ); r2 = i4int_to_r8int ( ilo, ihi, ir, rlo, rhi ); cout << " " << setw(12) << r << " " << setw(6) << ir << " " << setw(12) << r2 << "\n"; } return; } //****************************************************************************80 void perm0_check_test ( ) //****************************************************************************80 // // Purpose: // // PERM0_CHECK_TEST tests PERM0_CHECK. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 24 May 2015 // // Author: // // John Burkardt // { bool check; int n = 5; int p1[5] = { 5, 2, 3, 4, 1 }; int p2[5] = { 4, 1, 3, 0, 2 }; int p3[5] = { 0, 2, 1, 3, 2 }; cout << "\n"; cout << "PERM0_CHECK_TEST\n"; cout << " PERM0_CHECK checks a permutation of 0, ..., N-1.\n"; cout << "\n"; i4vec_transpose_print ( n, p1, " Permutation 1:" ); check = perm0_check( n, p1 ); i4vec_transpose_print ( n, p2, " Permutation 2:" ); check = perm0_check( n, p2 ); i4vec_transpose_print ( n, p3, " Permutation 3:" ); check = perm0_check( n, p3 ); return; } //****************************************************************************80 void perm0_uniform_test ( ) //****************************************************************************80 // // Purpose: // // PERM0_UNIFORM_TEST tests PERM0_UNIFORM. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 23 May 2015 // // Author: // // John Burkardt // { int i; int n = 10; int *p; int seed; int test; cout << "\n"; cout << "PERM0_UNIFORM_TEST\n"; cout << " PERM0_UNIFORM randomly selects a permutation of 0,...,N-1.\n"; cout << "\n"; seed = 123456789; for ( test = 1; test <= 5; test++ ) { p = perm0_uniform_new ( n, seed ); cout << " "; for ( i = 0; i < n; i++ ) { cout << setw(4) << p[i]; } cout << "\n"; delete [] p; } return; } //****************************************************************************80 void perm1_check_test ( ) //****************************************************************************80 // // Purpose: // // PERM1_CHECK_TEST tests PERM1_CHECK. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 24 May 2015 // // Author: // // John Burkardt // { bool check; int n = 5; int p1[5] = { 5, 2, 3, 4, 1 }; int p2[5] = { 4, 1, 3, 0, 2 }; int p3[5] = { 0, 2, 1, 3, 2 }; cout << "\n"; cout << "PERM1_CHECK_TEST\n"; cout << " PERM1_CHECK checks a permutation of 1, ..., N.\n"; cout << "\n"; i4vec_transpose_print ( n, p1, " Permutation 1:" ); check = perm1_check( n, p1 ); i4vec_transpose_print ( n, p2, " Permutation 2:" ); check = perm1_check( n, p2 ); i4vec_transpose_print ( n, p3, " Permutation 3:" ); check = perm1_check( n, p3 ); return; } //****************************************************************************80 void perm1_uniform_test ( ) //****************************************************************************80 // // Purpose: // // PERM1_UNIFORM_TEST tests PERM1_UNIFORM. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 23 May 2015 // // Author: // // John Burkardt // { int i; int n = 10; int *p; int seed; int test; cout << "\n"; cout << "PERM1_UNIFORM_TEST\n"; cout << " PERM1_UNIFORM randomly selects a permutation of 1,...,N.\n"; cout << "\n"; seed = 123456789; for ( test = 1; test <= 5; test++ ) { p = perm1_uniform_new ( n, seed ); cout << " "; for ( i = 0; i < n; i++ ) { cout << setw(4) << p[i]; } cout << "\n"; delete [] p; } return; } //****************************************************************************80 void r8_abs_test ( ) //****************************************************************************80 // // Purpose: // // R8_ABS_TEST tests R8_ABS. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 18 August 2010 // // Author: // // John Burkardt // { double r8; double r8_absolute; double r8_hi = 5.0; double r8_lo = -3.0; int seed; int test; int test_num = 10; seed = 123456789; cout << "\n"; cout << "R8_ABS_TEST\n"; cout << " R8_ABS returns the absolute value of an R8.\n"; cout << "\n"; cout << " X R8_ABS(X)\n"; cout << "\n"; for ( test = 1; test <= test_num; test++ ) { r8 = r8_uniform_ab ( r8_lo, r8_hi, seed ); r8_absolute = r8_abs ( r8 ); cout << " " << setw(10) << r8 << " " << setw(10) << r8_absolute << "\n"; } return; } //****************************************************************************80 void r8_acos_test ( ) //****************************************************************************80 // // Purpose: // // R8_ACOS_TEST tests R8_ACOS. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 25 July 2014 // // Author: // // John Burkardt // { double c; int test; cout << "\n"; cout << "R8_ACOS_TEST\n"; cout << " R8_ACOS computes the arc-cosine of an angle.\n"; cout << "\n"; cout << " C R8_ACOS(C) ACOS(C)\n"; cout << "\n"; for ( test = -1; test <= 13; test++ ) { c = ( double ) ( test - 6 ) / ( double ) ( 6 ); cout << setw(14) << c << " " << setw(14) << r8_acos ( c ); if ( -1.0 <= c && c <= 1.0 ) { cout << " " << setw(14) << acos ( c ); } cout << "\n"; } return; } //****************************************************************************80 void r8_acosh_test ( ) //****************************************************************************80 // // Purpose: // // R8_ACOSH_TEST tests R8_ACOSH. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 25 July 2014 // // Author: // // John Burkardt // { double a; int test; double x; double x2; cout << "\n"; cout << "R8_ACOSH_TEST\n"; cout << " R8_ACOSH computes the arc-hyperbolic-cosine of an angle.\n"; cout << "\n"; cout << " X A=R8_ACOSH(X) COSH(A)\n"; cout << "\n"; for ( test = 0; test <= 8; test++ ) { x = 1.0 + ( double ) ( test ) / 2.0; a = r8_acosh ( x ); x2 = cosh ( a ); cout << setw(14) << x << " " << setw(14) << a << " " << setw(14) << x2 << "\n"; } return; } //****************************************************************************80 void r8_asinh_test ( ) //****************************************************************************80 // // Purpose: // // R8_ASINH_TEST tests R8_ASINH. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 02 June 2007 // // Author: // // John Burkardt // { double a; int i; double x; double x2; cout << "\n"; cout << "R8_ASINH_TEST\n"; cout << " R8_ASINH computes the inverse hyperbolic sine\n"; cout << " of a given value.\n"; cout << "\n"; cout << " X R8_ASINH(X) SINH(R8_ASINH(X))\n"; cout << "\n"; for ( i = 0; i <= 10; i++ ) { x = 1.0 + ( ( double ) i ) / 5.0; a = r8_asinh ( x ); x2 = sinh ( a ); cout << " " << setw(10) << x << " " << setw(10) << a << " " << setw(10) << x2 << "\n"; } return; } //****************************************************************************80 void r8_atan_test ( ) //****************************************************************************80 // // Purpose: // // R8_ATAN_TEST tests R8_ATAN. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 17 July 2010 // // Author: // // John Burkardt // { # define TEST_NUM 8 int test; double x; double xtest[TEST_NUM] = { 1.0, 1.0, 0.0, -1.0, -1.0, -1.0, 0.0, 1.0 }; double y; double ytest[TEST_NUM] = { 0.0, 1.0, 1.0, 1.0, 0.0, -1.0, -1.0, -1.0 }; cout << "\n"; cout << "R8_ATAN_TEST\n"; cout << " R8_ATAN computes the arc-tangent given Y and X;\n"; cout << " ATAN2 is the system version of this routine.\n"; cout << "\n"; cout << " X Y ATAN2(Y,X) R8_ATAN(Y,X)\n"; cout << "\n"; for ( test = 0; test < TEST_NUM; test++ ) { x = xtest[test]; y = ytest[test]; cout << " " << setw(14) << x << " " << setw(14) << y << " " << setw(14) << atan2 ( y, x ) << " " << setw(14) << r8_atan ( y, x ) << "\n"; } return; # undef TEST_NUM } //****************************************************************************80 void r8_atanh_test ( ) //****************************************************************************80 // // Purpose: // // R8_ATANH_TEST tests R8_ATANH. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 02 June 2007 // // Author: // // John Burkardt // { double a; int i; double x; double x2; cout << "\n"; cout << "R8_ATANH_TEST\n"; cout << " R8_ATANH computes the inverse hyperbolic tangent\n"; cout << " of a given value.\n"; cout << "\n"; cout << " X R8_ATANH(X) TANH(R8_ATANH(X))\n"; cout << "\n"; for ( i = -2; i <= 9; i++ ) { x = ( ( double ) i ) / 10.0; a = r8_atanh ( x ); x2 = tanh ( a ); cout << " " << setw(10) << x << " " << setw(10) << a << " " << setw(10) << x2 << "\n"; } return; } //****************************************************************************80 void r8_big_test ( ) //****************************************************************************80 // // Purpose: // // R8_BIG_TEST tests R8_BIG. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 08 November 2014 // // Author: // // John Burkardt // { cout << "\n"; cout << "R8_BIG_TEST\n"; cout << " R8_BIG returns a 'big' R8 value;\n"; cout << "\n"; cout << " R8_BIG = " << r8_big ( ) << "\n"; return; } //****************************************************************************80 void r8_cas_test ( ) //****************************************************************************80 // // Purpose: // // R8_CAS_TEST tests R8_CAS. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 13 September 2006 // // Author: // // John Burkardt // { # define TEST_NUM 12 int test; double x; cout << "\n"; cout << "R8_CAS_TEST\n"; cout << " R8_CAS evaluates the casine of a number.\n"; cout << "\n"; cout << " X R8_CAS ( X )\n"; cout << "\n"; for ( test = 0; test <= TEST_NUM; test++ ) { x = r8_pi ( ) * ( double ) ( test ) / ( double ) ( TEST_NUM ); cout << " " << setw(14) << x << " " << setw(14) << r8_cas ( x ) << "\n"; } return; # undef TEST_NUM } //****************************************************************************80 void r8_ceiling_test ( ) //****************************************************************************80 // // Purpose: // // R8_CEILING_TEST tests R8_CEILING. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 13 September 2006 // // Author: // // John Burkardt // { int i; double rval; double rval_rounded; cout << "\n"; cout << "R8_CEILING_TEST\n"; cout << " R8_CEILING rounds a value up.\n"; cout << "\n"; cout << " X R8_CEILING(X)\n"; cout << "\n"; for ( i = -6; i <= 6; i++ ) { rval = ( double ) ( i ) / 5.0; rval_rounded = r8_ceiling ( rval ); cout << " " << setw(14) << rval << " " << setw(14) << rval_rounded << "\n"; } return; } //****************************************************************************80 void r8_choose_test ( ) //****************************************************************************80 // // Purpose: // // R8_CHOOSE_TEST tests R8_CHOOSE. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 26 July 2014 // // Author: // // John Burkardt // { double cnk; int k; int n; cout << "\n"; cout << "R8_CHOOSE_TEST\n"; cout << " R8_CHOOSE evaluates C(N,K).\n"; cout << "\n"; cout << " N K CNK\n"; for ( n = 0; n <= 5; n++ ) { cout << "\n"; for ( k = 0; k <= n; k++ ) { cnk = r8_choose ( n, k ); cout << setw(10) << n << " " << setw(8) << k << " " << setw(14) << cnk << "\n"; } } return; } //****************************************************************************80 void r8_cosd_test ( ) //****************************************************************************80 // // Purpose: // // R8_COSD_TEST tests R8_COSD. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 10 January 2015 // // Author: // // John Burkardt // { double angle; int i; cout << "\n"; cout << "R8_COSD_TEST\n"; cout << " R8_COSD computes the cosine of an angle\n"; cout << " given in degrees.\n"; cout << "\n"; cout << " ANGLE R8_COSD(ANGLE)\n"; cout << "\n"; for ( i = 0; i <= 360; i = i + 15 ) { angle = ( double ) ( i ); cout << " " << setw(8) << angle << " " << setw(14) << r8_cosd ( angle ) << "\n"; } return; } //****************************************************************************80 void r8_cotd_test ( ) //****************************************************************************80 // // Purpose: // // R8_COTD_TEST tests R8_COTD. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 12 January 2015 // // Author: // // John Burkardt // { double angle; int i; cout << "\n"; cout << "R8_COTD_TEST\n"; cout << " R8_COTD computes the cotangent of an angle\n"; cout << " given in degrees.\n"; cout << "\n"; cout << " ANGLE R8_COTD(ANGLE)\n"; cout << "\n"; for ( i = 0; i <= 360; i = i + 15 ) { angle = ( double ) ( i ); if ( i % 180 == 0 ) { cout << " " << setw(8) << angle << " Undefined\n"; } else { cout << " " << setw(8) << angle << " " << setw(14) << r8_cotd ( angle ) << "\n"; } } return; } //****************************************************************************80 void r8_cscd_test ( ) //****************************************************************************80 // // Purpose: // // R8_CSCD_TEST tests R8_CSCD. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 12 January 2015 // // Author: // // John Burkardt // { double angle; int i; cout << "\n"; cout << "R8_CSCD_TEST\n"; cout << " R8_CSCD computes the cosecant of an angle\n"; cout << " given in degrees.\n"; cout << "\n"; cout << " ANGLE R8_CSCD(ANGLE)\n"; cout << "\n"; for ( i = 0; i <= 360; i = i + 15 ) { angle = ( double ) ( i ); if ( i % 180 == 0 ) { cout << " " << setw(8) << angle << " Undefined\n"; } else { cout << " " << setw(8) << angle << " " << setw(14) << r8_cscd ( angle ) << "\n"; } } return; } //****************************************************************************80 void r8_cube_root_test ( ) //****************************************************************************80 // // Purpose: // // R8_CUBE_ROOT_TEST tests R8_CUBE_ROOT. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 26 July 2014 // // Author: // // John Burkardt // { double a; double b; int i; int seed; double x1; double y; double x2; cout << "\n"; cout << "R8_CUBE_ROOT_TEST\n"; cout << " R8_CUBE_ROOT computes the cube root of an R8.\n"; cout << "\n"; cout << " X Y Y^3\n"; cout << "\n"; a = -10.0; b = +10.0; seed = 123456789; for ( i = 1; i <= 10; i++ ) { x1 = r8_uniform_ab ( a, b, seed ); y = r8_cube_root ( x1 ); x2 = pow ( y, 3 ); cout << setw(14) << x1 << " " << setw(14) << y << " " << setw(14) << x2 << "\n"; } return; } //****************************************************************************80 void r8_diff_test ( ) //****************************************************************************80 // // Purpose: // // R8_DIFF_TEST tests R8_DIFF. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 09 September 2005 // // Author: // // John Burkardt // { # define TEST_NUM 15 int ndig = 3; int test; double x = 1.0; double y; double y_test[TEST_NUM] = { 0.0625, 0.125, 0.25, 0.50, 0.874, 0.876, 0.90, 0.95, 0.99, 1.0, 1.01, 1.05, 1.10, 3.0, 10.0 }; cout << "\n"; cout << "R8_DIFF_TEST\n"; cout << " R8_DIFF computes a difference X-Y to a given\n"; cout << " number of binary places.\n"; cout << "\n"; cout << " For this test, we use " << ndig << " binary places.\n"; cout << "\n"; cout << " X Y X-Y R8_DIFF(X,Y)\n"; cout << "\n"; for ( test = 0; test < TEST_NUM; test++ ) { y = y_test[test]; cout << " " << setw(10) << x << " " << setw(10) << y << " " << setw(10) << x-y << " " << setw(10) << r8_diff ( x, y, ndig ) << "\n"; } return; # undef TEST_NUM } //****************************************************************************80 void r8_digit_test ( ) //****************************************************************************80 // // Purpose: // // R8_DIGIT_TEST tests R8_DIGIT. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 08 September 2005 // // Author: // // John Burkardt // { # define MAXDIG 20 int idigit; double x; x = r8_pi ( ); cout << "\n"; cout << "R8_DIGIT_TEST\n"; cout << " R8_DIGIT extracts decimal digits.\n"; cout << "\n"; cout << " Here, we get digits of " << x << "\n"; cout << "\n"; cout << " "; for ( idigit = -2; idigit <= MAXDIG; idigit++ ) { cout << setw(3) << idigit; } cout << "\n"; cout << " "; for ( idigit = -2; idigit <= MAXDIG; idigit++ ) { cout << setw(3) << r8_digit ( x, idigit ); } cout << "\n"; return; # undef MAXDIG } //****************************************************************************80 void r8_e_test ( ) //****************************************************************************80 // // Purpose: // // R8_E_TEST tests R8_E. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 07 February 2015 // // Author: // // John Burkardt // { int i; int n; double value1; double value2; cout << "\n"; cout << "R8_E_TEST\n"; cout << " R8_E returns the value of E.\n"; cout << " Compare E to (1+1/n)^n\n"; value1 = r8_e ( ); cout << " R8_E = " << value1 << "\n"; cout << "\n"; cout << " N Estimate Error\n"; cout << "\n"; n = 1; for ( i = 0; i <= 20; i++ ) { value2 = pow ( ( double ) ( n + 1 ) / ( double ) ( n ), n ); cout << " " << setw(8) << n << " " << setw(14) << value2 << " " << setw(14) << fabs ( value1 - value2 ) << "\n"; n = n * 2; } return; } //****************************************************************************80 void r8_epsilon_test ( ) //****************************************************************************80 // // Purpose: // // R8_EPSILON_TEST tests R8_EPSILON. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 01 September 2012 // // Author: // // John Burkardt // { double r; double s; streamsize ss; double t; cout << "\n"; cout << "R8_EPSILON_TEST\n"; cout << " R8_EPSILON produces the R8 roundoff unit.\n"; cout << "\n"; // // Save the current precision. // ss = cout.precision ( ); r = r8_epsilon ( ); cout << " R = R8_EPSILON() = " << setprecision(16) << setw(24) << r << "\n"; s = 1.0 + r; t = s - 1.0; cout << " ( 1 + R ) - 1 = " << setprecision(16) << setw(24) << t << "\n"; s = 1.0 + ( r / 2.0 ); t = s - 1.0; cout << " ( 1 + (R/2) ) - 1 = " << setw(10) << t << "\n"; // // Restore the default precision. // cout.precision ( ss ); return; } //****************************************************************************80 void r8_epsilon_compute_test ( ) //****************************************************************************80 // // Purpose: // // R8_EPSILON_COMPUTE_TEST tests R8_EPSILON_COMPUTE. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 01 September 2012 // // Author: // // John Burkardt // { double r; double s; streamsize ss; double t; cout << "\n"; cout << "R8_EPSILON_COMPUTE_TEST\n"; cout << " R8_EPSILON_COMPUTE computes the R8 roundoff unit.\n"; cout << "\n"; // // Save the current precision. // ss = cout.precision ( ); r = r8_epsilon_compute ( ); cout << " R = R8_EPSILON_COMPUTE() = " << setprecision(16) << setw(24) << r << "\n"; s = 1.0 + r; t = s - 1.0; cout << " ( 1 + R ) - 1 = " << setprecision(16) << setw(24) << t << "\n"; s = 1.0 + ( r / 2.0 ); t = s - 1.0; cout << " ( 1 + (R/2) ) - 1 = " << setw(10) << t << "\n"; // // Restore the default precision. // cout.precision ( ss ); return; } //****************************************************************************80 void r8_factorial_test ( ) //****************************************************************************80 // // Purpose: // // R8_FACTORIAL_TEST tests R8_FACTORIAL. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 27 December 2014 // // Author: // // John Burkardt // { double f1; double f2; int n; int n_data; streamsize ss; // // Save the current precision. // ss = cout.precision ( ); cout << "\n"; cout << "R8_FACTORIAL_TEST\n"; cout << " R8_FACTORIAL evaluates the factorial function.\n"; cout << "\n"; cout << " N Exact Computed\n"; cout << "\n"; n_data = 0; for ( ; ; ) { r8_factorial_values ( n_data, n, f1 ); if ( n_data == 0 ) { break; } f2 = r8_factorial ( n ); cout << " " << setw(4) << n << " " << setprecision(16) << setw(24) << f1 << " " << setprecision(16) << setw(24) << f2 << "\n"; } // // Restore the default precision. // cout.precision ( ss ); return; } //****************************************************************************80 void r8_factorial2_test ( ) //****************************************************************************80 // // Purpose: // // R8_FACTORIAL2_TEST tests R8_FACTORIAL2. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 08 February 2015 // // Author: // // John Burkardt // { double f1; double f2; int n; int n_data; streamsize ss; // // Save the current precision. // ss = cout.precision ( ); cout << "\n"; cout << "R8_FACTORIAL2_TEST\n"; cout << " R8_FACTORIAL2 evaluates the double factorial function.\n"; cout << "\n"; cout << " N Exact Computed\n"; cout << "\n"; n_data = 0; for ( ; ; ) { r8_factorial2_values ( n_data, n, f1 ); if ( n_data == 0 ) { break; } f2 = r8_factorial2 ( n ); cout << " " << setw(4) << n << " " << setprecision(16) << setw(24) << f1 << " " << setprecision(16) << setw(24) << f2 << "\n"; } // // Restore the default precision. // cout.precision ( ss ); return; } //****************************************************************************80 void r8_fall_test ( ) //****************************************************************************80 // // Purpose: // // R8_FALL_TEST tests R8_FALL. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 22 December 2014 // // Author: // // John Burkardt // { double f1; double f2; int n; int n_data; streamsize ss; double x; // // Save the current precision. // ss = cout.precision ( ); cout << "\n"; cout << "R8_FALL_TEST\n"; cout << " R8_FALL evaluates the falling factorial Fall(X,N).\n"; cout << "\n"; cout << " X N Exact Computed\n"; cout << "\n"; n_data = 0; for ( ; ; ) { r8_fall_values ( n_data, x, n, f1 ); if ( n_data == 0 ) { break; } f2 = r8_fall ( x, n ); cout << " " << setw(8) << x << " " << setw(4) << n << " " << setprecision(16) << setw(24) << f1 << " " << setprecision(16) << setw(24) << f2 << "\n"; } // // Restore the default precision. // cout.precision ( ss ); return; } //****************************************************************************80 void r8_fractional_test ( ) //****************************************************************************80 // // Purpose: // // R8_FRACTIONAL_TEST tests R8_FRACTIONAL. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 05 October 2010 // // Author: // // John Burkardt // { double fractional; double r8; double r8_hi = 5.0; double r8_lo = -3.0; int seed = 123456789; int test; int test_num = 10; cout << "\n"; cout << "R8_FRACTIONAL_TEST\n"; cout << " R8_FRACTIONAL returns the fractional part of an R8.\n"; cout << "\n"; cout << " X R8_FRACTIONAL ( X )\n"; cout << "\n"; for ( test = 1; test <= test_num; test++ ) { r8 = r8_uniform_ab ( r8_lo, r8_hi, seed ); fractional = r8_fractional ( r8 ); cout << " " << setw(14) << r8 << " " << setw(14) << fractional << "\n"; } return; } //****************************************************************************80 void r8_gamma_test ( ) //****************************************************************************80 // // Purpose: // // R8_GAMMA_TEST tests R8_GAMMA. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 23 April 2013 // // Author: // // John Burkardt // { double fx1; double fx2; int n_data; streamsize ss; double x; // // Save the current precision. // ss = cout.precision ( ); cout << "\n"; cout << "R8_GAMMA_TEST:\n"; cout << " R8_GAMMA evaluates the Gamma function.\n"; cout << "\n"; cout << " X GAMMA(X) R8_GAMMA(X)\n"; cout << "\n"; n_data = 0; for ( ; ; ) { gamma_values ( n_data, x, fx1 ); if ( n_data == 0 ) { break; } fx2 = r8_gamma ( x ); cout << " " << setw(12) << x << " " << setw(24) << setprecision(16) << fx1 << " " << setw(24) << setprecision(16) << fx2 << "\n"; } // // Restore the default precision. // cout.precision ( ss ); return; } //****************************************************************************80 void r8_gamma_log_test ( ) //****************************************************************************80 // // Purpose: // // R8_GAMMA_LOG_TEST tests R8_GAMMA_LOG. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 23 April 2013 // // Author: // // John Burkardt // { double fx1; double fx2; int n_data; streamsize ss; double x; // // Save the current precision. // ss = cout.precision ( ); cout << "\n"; cout << "R8_GAMMA_LOG_TEST:\n"; cout << " R8_GAMMA_LOG evaluates the logarithm of the Gamma function.\n"; cout << "\n"; cout << " X GAMMA_LOG(X) R8_GAMMA_LOG(X)\n"; cout << "\n"; n_data = 0; for ( ; ; ) { gamma_log_values ( n_data, x, fx1 ); if ( n_data == 0 ) { break; } fx2 = r8_gamma_log ( x ); cout << " " << setw(12) << x << " " << setw(24) << setprecision(16) << fx1 << " " << setw(24) << setprecision(16) << fx2 << "\n"; } // // Restore the default precision. // cout.precision ( ss ); return; } //****************************************************************************80 void r8_huge_test ( ) //****************************************************************************80 // // Purpose: // // R8_HUGE_TEST tests R8_HUGE. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 07 September 2005 // // Author: // // John Burkardt // { cout << "\n"; cout << "R8_HUGE_TEST\n"; cout << " R8_HUGE returns a 'huge' R8 value;\n"; cout << "\n"; cout << " R8_HUGE = " << r8_huge ( ) << "\n"; return; } //****************************************************************************80 void r8_log_2_test ( ) //****************************************************************************80 // // Purpose: // // R8_LOG_2_TEST tests R8_LOG_2. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 08 September 2005 // // Author: // // John Burkardt // { # define TEST_NUM 18 int test; double x; double x_test[TEST_NUM] = { 0.0, 1.0, 2.0, 3.0, 9.0, 10.0, 11.0, 99.0, 101.0, -1.0, -2.0, -3.0, -9.0, 0.5, 0.33, 0.25, 0.20, 0.01 }; cout << "\n"; cout << "R8_LOG_2_TEST\n"; cout << " R8_LOG_2: computes the logarithm base 2.\n"; cout << "\n"; cout << " X R8_LOG_2\n"; cout << "\n"; for ( test = 0; test < TEST_NUM; test++ ) { x = x_test[test]; cout << " " << setw(12) << x << " " << setw(12) << r8_log_2 ( x ) << "\n"; } return; # undef TEST_NUM } //****************************************************************************80 void r8_log_b_test ( ) //****************************************************************************80 // // Purpose: // // R8_LOG_B_TEST tests R8_LOG_B. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 11 September 2005 // // Author: // // John Burkardt // { # define TEST_NUM 10 double b; double b_test[TEST_NUM] = { 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 16.0, 32.0, 256.0 }; int test; double x; x = 16.0; cout << "\n"; cout << "R8_LOG_B_TEST\n"; cout << " R8_LOG_B computes the logarithm base B.\n"; cout << "\n"; cout << " X B R8_LOG_B\n"; cout << "\n"; for ( test = 0; test < TEST_NUM; test++ ) { b = b_test[test]; cout << " " << setw(12) << x << " " << setw(12) << b << " " << setw(12) << r8_log_b ( x, b ) << "\n"; } return; # undef TEST_NUM } //****************************************************************************80 void r8_mant_test ( ) //****************************************************************************80 // // Purpose: // // R8_MANT_TEST tests R8_MANT. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 06 January 2013 // // Author: // // John Burkardt // { int l; double r; int s; double x; x = -314.159; cout << "\n"; cout << "R8_MANT_TEST\n"; cout << " R8_MANT decomposes a value.\n"; cout << "\n"; cout << " Number to be decomposed: X = " << x << "\n"; r8_mant ( x, s, r, l ); cout << "\n"; cout << " X = " << s << " * " << r << " * 2 ^ " << l << "\n"; return; } //****************************************************************************80 void r8_max_test ( ) //****************************************************************************80 // // Purpose: // // R8_MAX_TEST tests R8_MAX. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 10 March 2015 // // Author: // // John Burkardt // { double a; double b; double c; int i; double r8_hi; double r8_lo; int seed; cout << "\n"; cout << "R8_MAX_TEST\n"; cout << " R8_MAX returns the maximum of two R8's.\n"; cout << "\n"; cout << " A B C=R8_MAX(A,B)\n"; cout << "\n"; r8_lo = -5.0; r8_hi = +5.0; seed = 123456789; for ( i = 0; i < 10; i++ ) { a = r8_uniform_ab ( r8_lo, r8_hi, seed ); b = r8_uniform_ab ( r8_lo, r8_hi, seed ); c = r8_max ( a, b ); cout << " " << setw(8) << a << " " << setw(8) << b << " " << setw(8) << c << "\n"; } return; # undef N } //****************************************************************************80 void r8_min_test ( ) //****************************************************************************80 // // Purpose: // // R8_MIN_TEST tests R8_MIN. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 10 March 2015 // // Author: // // John Burkardt // { double a; double b; double c; int i; double r8_hi; double r8_lo; int seed; cout << "\n"; cout << "R8_MIN_TEST\n"; cout << " R8_MIN returns the minimum of two R8's.\n"; cout << "\n"; cout << " A B C=R8_MIN(A,B)\n"; cout << "\n"; r8_lo = -5.0; r8_hi = +5.0; seed = 123456789; for ( i = 0; i < 10; i++ ) { a = r8_uniform_ab ( r8_lo, r8_hi, seed ); b = r8_uniform_ab ( r8_lo, r8_hi, seed ); c = r8_min ( a, b ); cout << " " << setw(8) << a << " " << setw(8) << b << " " << setw(8) << c << "\n"; } return; # undef N } //****************************************************************************80 void r8_mod_test ( ) //****************************************************************************80 // // Purpose: // // R8_MOD_TEST tests R8_MOD. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 14 June 2007 // // Author: // // John Burkardt // { int seed = 123456789; int test; int test_num = 10; double x; double x_hi = 10.0; double x_lo = -10.0; double y; double z1; double z2; cout << "\n"; cout << "R8_MOD_TEST\n"; cout << " R8_MOD returns the remainder after division.\n"; cout << " R8_MOD ( X, Y ) has the same sign as X.\n"; cout << "\n"; cout << " X Y FMOD(X,Y) R8_MOD(X,Y)\n"; cout << "\n"; for ( test = 1; test <= test_num; test++ ) { x = r8_uniform_ab ( x_lo, x_hi, seed ); y = r8_uniform_ab ( x_lo, x_hi, seed ); z1 = fmod ( x, y ); z2 = r8_mod ( x, y ); cout << " " << setw(12) << x << " " << setw(12) << y << " " << setw(12) << z1 << " " << setw(12) << z2 << "\n"; } return; } //****************************************************************************80 void r8_modp_test ( ) //****************************************************************************80 // // Purpose: // // R8_MODP_TEST tests R8_MODP. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 14 June 2007 // // Author: // // John Burkardt // { int seed = 123456789; int test; int test_num = 10; double x; double x_hi = 10.0; double x_lo = -10.0; double y; double z1; double z2; cout << "\n"; cout << "R8_MODP_TEST\n"; cout << " R8_MODP returns the remainder after division.\n"; cout << " R8_MODP ( X, Y ) is positive.\n"; cout << "\n"; cout << " X Y FMOD(X,Y) R8_MODP(X,Y)\n"; cout << "\n"; for ( test = 1; test <= test_num; test++ ) { x = r8_uniform_ab ( x_lo, x_hi, seed ); y = r8_uniform_ab ( x_lo, x_hi, seed ); z1 = fmod ( x, y ); z2 = r8_modp ( x, y ); cout << " " << setw(12) << x << " " << setw(12) << y << " " << setw(12) << z1 << " " << setw(12) << z2 << "\n"; } return; } //****************************************************************************80 void r8_mop_test ( ) //****************************************************************************80 // // Purpose: // // R8_MOP_TEST tests R8_MOP. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 06 December 2014 // // Author: // // John Burkardt // { int i4; int i4_max; int i4_min; double r8; int seed = 123456789; int test; cout << "\n"; cout << "R8_MOP_TEST\n"; cout << " R8_MOP evaluates (-1.0)^I4 as an R8.\n"; cout << "\n"; cout << " I4 R8_MOP(I4)\n"; cout << "\n"; i4_min = -100; i4_max = +100; for ( test = 1; test <= 10; test++ ) { i4 = i4_uniform_ab ( i4_min, i4_max, seed ); r8 = r8_mop ( i4 ); cout << " " << setw(4) << i4 << " " << setw(4) <