| 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 | |
| 20 | static void make_float_bigendian (float * x); |
| 21 | static void make_double_bigendian (double * x); |
| 22 | |
| 23 | static void |
| 24 | make_float_bigendian (float * x) |
| 25 | { |
| 26 | union { |
| 27 | float f; |
| 28 | unsigned char b[4]; |
| 29 | } u,v; |
| 30 | |
| 31 | u.f = *x ; |
| 32 | |
| 33 | v.b[0]=u.b[3] ; |
| 34 | v.b[1]=u.b[2] ; |
| 35 | v.b[2]=u.b[1] ; |
| 36 | v.b[3]=u.b[0] ; |
| 37 | |
| 38 | *x=v.f ; |
| 39 | } |
| 40 | |
| 41 | static void |
| 42 | make_double_bigendian (double * x) |
| 43 | { |
| 44 | union { |
| 45 | double d; |
| 46 | unsigned char b[8]; |
| 47 | } u,v; |
| 48 | |
| 49 | u.d = *x ; |
| 50 | |
| 51 | v.b[0]=u.b[7] ; |
| 52 | v.b[1]=u.b[6] ; |
| 53 | v.b[2]=u.b[5] ; |
| 54 | v.b[3]=u.b[4] ; |
| 55 | v.b[4]=u.b[3] ; |
| 56 | v.b[5]=u.b[2] ; |
| 57 | v.b[6]=u.b[1] ; |
| 58 | v.b[7]=u.b[0] ; |
| 59 | |
| 60 | *x=v.d ; |
| 61 | } |