Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.8 KiB

  1. #include <windows.h>
  2. #include "dsdmo.h"
  3. double LogNorm[32] =
  4. {
  5. 1, 1, 1.5, 1, 1.75, 1.4, 1.17, 1, 1.88, 1.76, 1.5, 1.36, 1.25, 1.15, 1.07,
  6. 1, 1.94, 1.82, 1.72, 1.63, 1.55, 1.48, 1.41, 1.35, 1.29, 1.24, 1.19, 1.15,
  7. 1.11, 1.07, 1.03, 1
  8. };
  9. float mylog( float finput, unsigned long maxexponent)
  10. {
  11. unsigned long mantissa, exponent, exponentwidth ;
  12. long input, output, sign;
  13. #ifdef DONTUSEi386
  14. _asm {
  15. fld finput
  16. fistp input
  17. }
  18. #else
  19. input = (int)finput;
  20. #endif
  21. /*
  22. * Separate the sign bit
  23. */
  24. sign = input & 0x80000000L ; /* Preserve sign */
  25. /*
  26. * Separate mantissa bits from the sign and
  27. * complement them if original input was negative
  28. */
  29. mantissa = sign ? -input : input;
  30. /*
  31. * Attempt to normalize the input to form the mantissa and
  32. * thereby calculate the actual exponent.
  33. */
  34. exponent = maxexponent ;
  35. while( (mantissa < 0x80000000) && (exponent > 0) ) {
  36. mantissa = mantissa << 1 ;
  37. exponent-- ;
  38. }
  39. /*
  40. * If normalization was successful, mask off the MSB (since it
  41. * will be implied by a non-zero exponent) and adjust the exponent value
  42. */
  43. if( mantissa >= 0x80000000 ) {
  44. mantissa = mantissa & 0x7FFFFFFF ;
  45. exponent++ ;
  46. }
  47. /*
  48. * Find the width of the exponent field required to represent
  49. * maxeponent and assemble the sign, exponent and mantissa fields
  50. * based on that width.
  51. */
  52. if( maxexponent > 15 )
  53. exponentwidth = 5 ;
  54. else if( maxexponent > 7 )
  55. exponentwidth = 4 ;
  56. else if( maxexponent > 3 )
  57. exponentwidth = 3 ;
  58. else
  59. exponentwidth = 2 ;
  60. if (sign == 0x80000000L)
  61. output = sign | ~((exponent << (31-exponentwidth)) | (mantissa >> exponentwidth)) ;
  62. else
  63. output = sign | ((exponent << (31-exponentwidth)) | (mantissa >> exponentwidth)) ;
  64. float x = (float)output;
  65. return(x);
  66. }