flrtstl.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. long double floorl(), ldexpl(), frexpl();
  2. #define N 16382
  3. void prnum();
  4. int printf();
  5. void exit();
  6. void main()
  7. {
  8. long double x, f, y, last, z, z0, y1;
  9. int i, k, e, e0, errs;
  10. errs = 0;
  11. f = 0.1L;
  12. x = f;
  13. last = x;
  14. z0 = frexpl( x, &e0 );
  15. printf( "frexpl(%.2Le) = %.5Le, %d\n", x, z0, e0 );
  16. k = 0;
  17. for( i=0; i<N+5; i++ )
  18. {
  19. y = ldexpl( f, k );
  20. if( y != x )
  21. {
  22. printf( "ldexpl(%.1Le, %d) = %.5Le, s.b. %.5Le\n",
  23. f, k, y, x );
  24. ++errs;
  25. }
  26. z = frexpl( y, &e );
  27. if( (e != k+e0) || (z != z0) )
  28. {
  29. printf( "frexpl(%.1Le) = %.5Le, %d; s.b. %.5Le, %d\n",
  30. y, z, e, z0, k+e0 );
  31. ++errs;
  32. }
  33. x += x;
  34. if( x == last )
  35. break;
  36. last = x;
  37. k += 1;
  38. }
  39. printf( "i = %d\n", k );
  40. prnum( "last y =", &y );
  41. printf("\n");
  42. f = 0.1L;
  43. x = f;
  44. last = x;
  45. k = 0;
  46. for( i=0; i<N+64; i++ )
  47. {
  48. y = ldexpl( f, k );
  49. if( y != x )
  50. {
  51. printf( "ldexpl(%.1Le, %d) = %.5Le, s.b. %.5Le\n",
  52. f, k, y, x );
  53. ++errs;
  54. }
  55. z = frexpl( y, &e );
  56. if(
  57. #if 1
  58. (e > -N+1) &&
  59. #endif
  60. ((e != k+e0) || (z != z0)) )
  61. {
  62. printf( "frexpl(%.1Le) = %.5Le, %d; s.b. %.5Le, %d\n",
  63. y, z, e, z0, k+e0 );
  64. ++errs;
  65. }
  66. y1 = ldexpl( z, e );
  67. if( y1 != y )
  68. {
  69. printf( "ldexpl(%.1Le, %d) = %.5Le, s.b. %.5Le\n",
  70. z, e, y1, y );
  71. ++errs;
  72. }
  73. x *= 0.5L;
  74. if( x == 0.0L )
  75. break;
  76. if( x == last )
  77. break;
  78. last = x;
  79. k -= 1;
  80. }
  81. printf( "i = %d\n", k );
  82. prnum( "last y =", &y );
  83. printf( "\n%d errors\n", errs );
  84. exit(0);
  85. }
  86. void prnum(str, x)
  87. char *str;
  88. unsigned short *x;
  89. {
  90. int i;
  91. printf( "%s ", str );
  92. printf( "%.5Le = ", *(long double *)x );
  93. for( i=0; i<5; i++ )
  94. printf( "%04x ", *x++ );
  95. }