home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / mathfi / mathfix.c
Text File  |  1994-03-24  |  2KB  |  116 lines

  1. double check_dbl( double d, int *flip )
  2. {
  3.  *flip = 0;
  4.  
  5.  if ( d > (PI/2.0) ) {
  6.     do {
  7.        *flip ^= 1;
  8.        d -= PI;
  9.        } while (d > PI/2.0);
  10.     }
  11.  else if ( d < -(PI/2.0) ) {
  12.     do {
  13.        *flip ^= 1;
  14.        d += PI;
  15.        } while (d < -(PI/2.0) );
  16.     }
  17.  return( d );
  18. }
  19. #ifndef NOLNGDBL
  20. long double check_dbll( long double d, int *flip )
  21. {
  22.  *flip = 0;
  23.  
  24.  if ( d > (PI/2.0) ) {
  25.     do {
  26.        *flip ^= 1;
  27.        d -= PI;
  28.        } while (d > PI/2.0);
  29.     }
  30.  else if ( d < -(PI/2.0) ) {
  31.     do {
  32.        *flip ^= 1;
  33.        d += PI;
  34.        } while (d < -(PI/2.0) );
  35.     }
  36.  return( d );
  37. }
  38. #endif
  39.  
  40. double xtan( double t )
  41. {
  42.  if ( t <= -(PI/2.0) ) {
  43.     while ( t < -(PI/2.0) )
  44.     t += PI;
  45.     }
  46.  else if ( t > (PI/2.0) ) {
  47.     while ( t > PI/2.0 )
  48.     t -= PI;
  49.     }
  50.  return( tan( t ) );
  51. }
  52.  
  53. #ifndef NOLNGDBL
  54. LONG_DOUBLE xtanl( LONG_DOUBLE t )
  55. {
  56.  if ( t <= -(PI/2.0) ) {
  57.     while ( t < -(PI/2.0) )
  58.     t += PI;
  59.     }
  60.  else if ( t > (PI/2.0) ) {
  61.     while ( t > PI/2.0 )
  62.     t -= PI;
  63.     }
  64.  return( tanl( t ) );
  65. }
  66. #endif
  67.  
  68. double xsin( double t )
  69. {
  70.  int f;
  71.  t = check_dbl(t, &f );
  72.  t = sin( t );
  73.  if ( f )
  74.     return( -t );
  75.  else
  76.     return( t );
  77. }
  78.  
  79. #ifndef NOLNGDBL
  80. LONG_DOUBLE xsinl( LONG_DOUBLE t )
  81. {
  82.  int f;
  83.  t = check_dbll(t, &f );
  84.  t = sinl( t );
  85.  if ( f )
  86.     return( -t );
  87.  else
  88.     return( t );
  89. }
  90. #endif
  91.  
  92. double xcos( double t )
  93. {
  94.  int f;
  95.  t = check_dbl(t, &f );
  96.  t = cos( t );
  97.  if ( f )
  98.     return( -t );
  99.  else
  100.     return( t );
  101. }
  102.  
  103. #ifndef NOLNGDBL
  104. LONG_DOUBLE xcosl( LONG_DOUBLE t )
  105. {
  106.  int f;
  107.  t = check_dbll(t, &f );
  108.  t = cosl( t );
  109.  if ( f )
  110.     return( -t );
  111.  else
  112.     return( t );
  113. }
  114. #endif
  115.  
  116.