Skip to main content
added 93 characters in body
Source Link
chux
  • 36.5k
  • 2
  • 43
  • 97

Suspected subtle bug

Try

  printf("%a\n", 0.866025403784438);
  printf("%a\n", sqrt(3)/2);
  printf("%a\n", 0.86602540378443865);
  printf("%a\n", 0.86602540378443864676372317075294);
  printf("%a\n", nextafter(sqrt(3)/2,0));

My output

0x1.bb67ae8584ca5p-1  // 5 ULP away from the best root3/2
0x1.bb67ae8584caap-1
0x1.bb67ae8584caap-1
0x1.bb67ae8584caap-1
0x1.bb67ae8584ca9p-1

Rather than code a less than precise value, use enough significant decimal digits to form the best floating point value.
For double, use DBL_DECIMAL_DIG or more significant digits.
DBL_DECIMAL_DIG is commonly 17.

typedef struct s_float2{
    double  x;
    double  y;
}   t_float2;

// (t_float2){-0.5, 0.866025403784438};
//                 12345678901234567
(t_float2){-0.5, 0.86602540378443865};

OTOH, perhaps OP wanted to start further away than closest double to sqrt(3)/2?

Suspected subtle bug

Try

  printf("%a\n", 0.866025403784438);
  printf("%a\n", sqrt(3)/2);
  printf("%a\n", 0.86602540378443865);
  printf("%a\n", 0.86602540378443864676372317075294);
  printf("%a\n", nextafter(sqrt(3)/2,0));

My output

0x1.bb67ae8584ca5p-1  // 5 ULP away from the best root3/2
0x1.bb67ae8584caap-1
0x1.bb67ae8584caap-1
0x1.bb67ae8584caap-1
0x1.bb67ae8584ca9p-1

Rather than code a less than precise value, use enough significant decimal digits to form the best floating point value.
For double, use DBL_DECIMAL_DIG or more significant digits.
DBL_DECIMAL_DIG is commonly 17.

typedef struct s_float2{
    double  x;
    double  y;
}   t_float2;

// (t_float2){-0.5, 0.866025403784438};
//                 12345678901234567
(t_float2){-0.5, 0.86602540378443865};

Suspected subtle bug

Try

  printf("%a\n", 0.866025403784438);
  printf("%a\n", sqrt(3)/2);
  printf("%a\n", 0.86602540378443865);
  printf("%a\n", 0.86602540378443864676372317075294);
  printf("%a\n", nextafter(sqrt(3)/2,0));

My output

0x1.bb67ae8584ca5p-1  // 5 ULP away from the best root3/2
0x1.bb67ae8584caap-1
0x1.bb67ae8584caap-1
0x1.bb67ae8584caap-1
0x1.bb67ae8584ca9p-1

Rather than code a less than precise value, use enough significant decimal digits to form the best floating point value.
For double, use DBL_DECIMAL_DIG or more significant digits.
DBL_DECIMAL_DIG is commonly 17.

typedef struct s_float2{
    double  x;
    double  y;
}   t_float2;

// (t_float2){-0.5, 0.866025403784438};
//                 12345678901234567
(t_float2){-0.5, 0.86602540378443865};

OTOH, perhaps OP wanted to start further away than closest double to sqrt(3)/2?

Source Link
chux
  • 36.5k
  • 2
  • 43
  • 97

Suspected subtle bug

Try

  printf("%a\n", 0.866025403784438);
  printf("%a\n", sqrt(3)/2);
  printf("%a\n", 0.86602540378443865);
  printf("%a\n", 0.86602540378443864676372317075294);
  printf("%a\n", nextafter(sqrt(3)/2,0));

My output

0x1.bb67ae8584ca5p-1  // 5 ULP away from the best root3/2
0x1.bb67ae8584caap-1
0x1.bb67ae8584caap-1
0x1.bb67ae8584caap-1
0x1.bb67ae8584ca9p-1

Rather than code a less than precise value, use enough significant decimal digits to form the best floating point value.
For double, use DBL_DECIMAL_DIG or more significant digits.
DBL_DECIMAL_DIG is commonly 17.

typedef struct s_float2{
    double  x;
    double  y;
}   t_float2;

// (t_float2){-0.5, 0.866025403784438};
//                 12345678901234567
(t_float2){-0.5, 0.86602540378443865};