1 /* $XConsortium: sfputd.c /main/3 1995/11/01 18:33:55 rswiston $ */
2 /***************************************************************
6 * THIS IS PROPRIETARY SOURCE CODE LICENSED BY *
9 * Copyright (c) 1995 AT&T Corp. *
10 * All Rights Reserved *
12 * This software is licensed by AT&T Corp. *
13 * under the terms and conditions of the license in *
14 * http://www.research.att.com/orgs/ssr/book/reuse *
16 * This software was created by the *
17 * Software Engineering Research Department *
18 * AT&T Bell Laboratories *
20 * For further information contact *
21 * gsf@research.att.com *
23 ***************************************************************/
26 /* Write out a double value in a portable format
28 ** Written by Kiem-Phong Vo (08/05/90)
32 _sfputd(Sfio_t* f, reg double v)
39 #define N_ARRAY (16*sizeof(double))
46 if(f->mode != SF_WRITE && _sfmode(f,SF_WRITE,0) < 0)
50 /* get the sign of v */
57 /* make the magnitude of v < 1 */
62 /* code the sign of v and exp */
68 /* write out the signs and the exp */
70 if(sfputc(f,n) < 0 || (w = sfputu(f,w)) < 0)
75 s = (ends = &c[0])+sizeof(c);
77 { /* get 2^SF_PRECIS precision at a time */
78 n = (int)(x = ldexp(v,SF_PRECIS));
84 /* last byte is not SF_MORE */
85 ends = &c[0] + sizeof(c) -1;
88 /* write out coded bytes */
90 w = SFWRITE(f,(Void_t*)s,n) == n ? w+n : -1;