]> git.nega.tv - josh/narcissus/commitdiff
Improve cos_pi polynomial
authorJoshua Simmons <josh@nega.tv>
Sat, 4 Mar 2023 14:28:34 +0000 (15:28 +0100)
committerJoshua Simmons <josh@nega.tv>
Sat, 4 Mar 2023 14:28:34 +0000 (15:28 +0100)
Optimising for absolute error rather than relative error performs
slightly better for the cos_pi polynomial.

libs/narcissus-maths/doc/sincostan.sollya
libs/narcissus-maths/src/sin_cos_pi.rs
libs/narcissus-maths/tests/exhaustive_f32.rs

index ef8280b37774f6ba792071b26893fc27c82c71e3..37f93d6de04facecbf07a9e9e1d926585d562525 100644 (file)
@@ -4,7 +4,6 @@
 
 R = [0;1/4];
 T = floating;
-E = relative;
 B = [|SG...|];
 
 // write fp values such that they always have a decimal point
@@ -126,7 +125,7 @@ B = [|D,SG...|];
 print("sin(pi x) in binary32");
 I = [|1,3,5,7|];
 F = sin(pi*x);
-P = fpminimax(F,I,B,R,T,E);
+P = fpminimax(F,I,B,R,T,relative);
 f32_data_write("F32_SIN_PI_7", P,F,R);
 f32_write_list("F32_SIN_PI_7", list_of_odd_coeff(P));
 print("\n");
@@ -136,7 +135,7 @@ B = [|SG...|];
 print("cos(pi x) in binary32");
 I = [|0,2,4,6,8|];
 F = cos(pi*x);
-P = fpminimax(F,I,B,R,T,E);
+P = fpminimax(F,I,B,R,T,absolute);
 f32_data_write("F32_COS_PI_8", P,F,R);
 f32_write_list("F32_COS_PI_8", list_of_even_coeff(P));
 print("\n");
@@ -147,7 +146,7 @@ print("tan(pi x) in binary32");
 I = [|1,3,5,7,9,11,13,15|];
 F = tan(pi*x);
 
-P = fpminimax(F,I,B,R,T,E);
+P = fpminimax(F,I,B,R,T,relative);
 
 f32_data_write("F32_TAN_PI", P,F,R);
 f32_write_list("F32_TAN_PI", list_of_odd_coeff(P));
index 7f96f070ddd1cd7100b25ba8961f2ad6b5c01c0d..bc0089c23e66f6d175db7333e4ad536d4c1f4f4d 100644 (file)
@@ -16,9 +16,9 @@ const F32_SIN_PI_7_K: [f32; 3] = unsafe {
 const F32_COS_PI_8_K: [f32; 4] = unsafe {
     std::mem::transmute::<[u32; 4], _>([
         0xc09de9e6, // -0x1.3bd3ccp2
-        0x4081e0dc, // 0x1.03c1b8p2
-        0xbfaadbe7, // -0x1.55b7cep0
-        0x3e6b4255, // 0x1.d684aap-3
+        0x4081e0db, // 0x1.03c1b6p2
+        0xbfaadb42, // -0x1.55b684p0
+        0x3e6b0f14, // 0x1.d61e28p-3
     ])
 };
 
index a522a54fd2f75be63f9122cbba71e9f9536fa373..af505c2d6a2e906b98769e935854f08a584acf44 100644 (file)
@@ -432,7 +432,7 @@ pub fn exhaustive_sin_pi() {
 pub fn exhaustive_cos_pi() {
     let errors = check_exhaustive_f32(ref_cos_pi_f32, |a| sin_cos_pi_f32(a).1, false);
     println!("COS: {errors:?}");
-    assert_eq!(errors.num_errors, 45_896_848);
+    assert_eq!(errors.num_errors, 45_882_714);
     assert_eq!(errors.max_error_ulp, 1);
 }