gsl_ieee-utils__standardize.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* ieee-utils/standardize.c
  2. *
  3. * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2007 Brian Gough
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. static void make_float_bigendian (float * x);
  20. static void make_double_bigendian (double * x);
  21. static void
  22. make_float_bigendian (float * x)
  23. {
  24. union {
  25. float f;
  26. unsigned char b[4];
  27. } u,v;
  28. u.f = *x ;
  29. v.b[0]=u.b[3] ;
  30. v.b[1]=u.b[2] ;
  31. v.b[2]=u.b[1] ;
  32. v.b[3]=u.b[0] ;
  33. *x=v.f ;
  34. }
  35. static void
  36. make_double_bigendian (double * x)
  37. {
  38. union {
  39. double d;
  40. unsigned char b[8];
  41. } u,v;
  42. u.d = *x ;
  43. v.b[0]=u.b[7] ;
  44. v.b[1]=u.b[6] ;
  45. v.b[2]=u.b[5] ;
  46. v.b[3]=u.b[4] ;
  47. v.b[4]=u.b[3] ;
  48. v.b[5]=u.b[2] ;
  49. v.b[6]=u.b[1] ;
  50. v.b[7]=u.b[0] ;
  51. *x=v.d ;
  52. }