s_copysign.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*******************************************************************************
  2. * *
  3. * File sign.c, *
  4. * Functions copysign and __signbitd. *
  5. * For PowerPC based machines. *
  6. * *
  7. * Copyright © 1991, 2001 Apple Computer, Inc. All rights reserved. *
  8. * *
  9. * Written by Ali Sazegari, started on June 1991. *
  10. * *
  11. * August 26 1991: no CFront Version 1.1d17 warnings. *
  12. * September 06 1991: passes the test suite with invalid raised on *
  13. * signaling nans. sane rom code behaves the same. *
  14. * September 24 1992: took the Ò#include support.hÓ out. *
  15. * Dcember 02 1992: PowerPC port. *
  16. * July 20 1994: __fabs added *
  17. * July 21 1994: deleted unnecessary functions: neg, COPYSIGNnew, *
  18. * and SIGNNUMnew. *
  19. * April 11 2001: first port to os x using gcc. *
  20. * removed fabs and deffered to gcc for direct *
  21. * instruction generation. *
  22. * *
  23. *******************************************************************************/
  24. #include <math.h>
  25. #include "../fp_private.h"
  26. /*******************************************************************************
  27. * *
  28. * Function copysign. *
  29. * Implementation of copysign for the PowerPC. *
  30. * *
  31. ********************************************************************************
  32. * Note: The order of the operands in this function is reversed from that *
  33. * suggested in the IEEE standard 754. *
  34. *******************************************************************************/
  35. libm_hidden_proto(copysign)
  36. double copysign ( double arg2, double arg1 )
  37. {
  38. union
  39. {
  40. dHexParts hex;
  41. double dbl;
  42. } x, y;
  43. /*******************************************************************************
  44. * No need to flush NaNs out. *
  45. *******************************************************************************/
  46. x.dbl = arg1;
  47. y.dbl = arg2;
  48. y.hex.high = y.hex.high & 0x7FFFFFFF;
  49. y.hex.high = ( y.hex.high | ( x.hex.high & dSgnMask ) );
  50. return y.dbl;
  51. }
  52. libm_hidden_def(copysign)