NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Error in returned value of sizeof(long double) in amd64?



sizeof(long double) reports 16 in both amd64 and arm64.  I think that amd64 uses 80-bit long double floats, and arm64 uses 128-bit long double floats.  See enclosed code.

What am I misunderstanding?
-Mike

amd64 gives: 9 is 8.999999999999999991326382620115964528, error is 0.000000000000000008673617379884035472, sizeof(long double)=16
arm64 gives: 9 is 8.999999999999999999999999999999986133, error is 0.000000000000000000000000000000013867, sizeof(long double)=16

#include <math.h>
#include <stdio.h>
int main(){
  // Compute:  arcsin (arccos(arctan(tan(cos(sin (9))))))    argument is in degrees

  long double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679L;
  long double x,y,z,ans;

  x = pi / 20.0L; // 9 degrees is pi/20
  y = tanl(cosl(sinl(x)));
  z = asinl(acosl(atanl(y)));

  ans = z * 180.0L / pi;  // Convert to degrees:  rads * 180/pi

  printf("9 is %38.36Lf, error is %38.36Lf, sizeof(long double)=%ld\n", ans,9.0L-ans,  sizeof(long double));
}



Home | Main Index | Thread Index | Old Index