2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 1989, 2011, Oracle and/or its affiliates. All rights reserved. 2N/A/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 2N/A/* All Rights Reserved */ 2N/A * Portions of this source code were derived from Berkeley 2N/A * 4.3 BSD under license from the Regents of the University of 2N/A * Generic XDR routines impelmentation. 2N/A * These are the "floating point" xdr routines used to (de)serialize 2N/A * most common data items. See xdr.h for more info on the interface to 2N/A * This routine works on Suns, 3b2, 68000s, 386 and Vaxen in a manner 2N/A * which is very efficient as bit twiddling is all that is needed. All 2N/A * other machines can use this code but the code is inefficient as 2N/A * various mathematical operations are used to generate the ieee format. 2N/A * In addition rounding errors may occur due to the calculations involved. 2N/A * To be most efficient, new machines should have their own ifdefs. 2N/A * The encoding routines will fail if the machines try to encode a 2N/A * ieee largest float = (2 ^ 128) * 0x1.fffff 2N/A * ieee smallest float = (2 ^ -127) * 0x1.00000 2N/A * ieee largest double = (2 ^ 1024) * 0x1.fffff 2N/A * ieee smallest double = (2 ^ -1023) * 0x1.00000 2N/A * The decoding routines assumes that the receiving machine can handle 2N/A * use a machine which can not represent these values, you will need 2N/A * to put ifdefs in the decode sections to identify areas of failure. 2N/A * What IEEE single precision floating point looks like this on a 2N/A/* Vax single precision floating point */ 2N/A {{
0x7f,
0xff,
0x0,
0xffff },
/* Max Vax */ 2N/A {
0x0,
0xff,
0x0 }},
/* Max IEEE */ 2N/A {{
0x0,
0x0,
0x0,
0x0 },
/* Min Vax */ 2N/A {
0x0,
0x0,
0x0 }}
/* Min IEEE */ 2N/A /* map these to subnormals */ 2N/A /* lose some precision */ 2N/A * Every machine can do this, its just not very efficient. 2N/A * In addtion, some rounding errors may occur do to the 2N/A * calculations involved. 2N/A /* over or under flowing ieee exponent */ 2N/A * Every machine can do this, its just not very 2N/A * efficient. It assumes that the decoding machine's 2N/A * float can represent any value in the range of 2N/A * ieee largest float = (2 ^ 128) * 0x1.fffff 2N/A * ieee smallest float = (2 ^ -127) * 0x1.00000 2N/A * In addtion, some rounding errors may occur do to the 2N/A * calculations involved. 2N/A exp -=
127;
/* subtract exponent base */ 2N/A f = (
val &
0x007fffff) *
0.00000011920928955078125;
2N/A * This routine works on Suns (Sky / 68000's) and Vaxen. 2N/A/* What IEEE double precision floating point looks like on a Vax */ 2N/A/* Vax double precision floating point */ 2N/A {{
0x7f,
0xff,
0x0,
0xffff,
0xffff,
0xffff },
/* Max Vax */ 2N/A {
0x0,
0x7ff,
0x0,
0x0 }},
/* Max IEEE */ 2N/A {{
0x0,
0x0,
0x0,
0x0,
0x0,
0x0},
/* Min Vax */ 2N/A {
0x0,
0x0,
0x0,
0x0 }}
/* Min IEEE */ 2N/A * Every machine can do this, its just not very efficient. 2N/A * In addtion, some rounding errors may occur do to the 2N/A * calculations involved. 2N/A /* over or under flowing ieee exponent */ 2N/A val[0] =
val[0] <<
11;
/* for the exponent */ 2N/A val[0] =
val[0] <<
20;
/* for the mantissa */ 2N/A * Every machine can do this, its just not very 2N/A * efficient. It assumes that the decoding machine's 2N/A * double can represent any value in the range of 2N/A * ieee largest double = (2 ^ 1024) * 0x1.fffffffffffff 2N/A * ieee smallest double = (2 ^ -1023) * 0x1.0000000000000 2N/A * In addtion, some rounding errors may occur do to the 2N/A * calculations involved. 2N/A exp -=
1023;
/* subtract exponent base */ 2N/A d = (
val[0] &
0x000fffff) *
0.00000095367431640625;
2N/A d += (
val[
1] *
0.0000000000000002220446049250313);
2N/A * The Sparc uses IEEE FP encoding, so just do a byte copy