[BACK]Return to g_ffmt.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / gdtoa

Annotation of src/lib/libc/gdtoa/g_ffmt.c, Revision 1.2

1.2     ! christos    1: /* $NetBSD: g_ffmt.c,v 1.1.1.1 2006/01/25 15:18:44 kleink Exp $ */
1.1       kleink      2:
                      3: /****************************************************************
                      4:
                      5: The author of this software is David M. Gay.
                      6:
                      7: Copyright (C) 1998 by Lucent Technologies
                      8: All Rights Reserved
                      9:
                     10: Permission to use, copy, modify, and distribute this software and
                     11: its documentation for any purpose and without fee is hereby
                     12: granted, provided that the above copyright notice appear in all
                     13: copies and that both that the copyright notice and this
                     14: permission notice and warranty disclaimer appear in supporting
                     15: documentation, and that the name of Lucent or any of its entities
                     16: not be used in advertising or publicity pertaining to
                     17: distribution of the software without specific, written prior
                     18: permission.
                     19:
                     20: LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
                     21: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
                     22: IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
                     23: SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     24: WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
                     25: IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
                     26: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
                     27: THIS SOFTWARE.
                     28:
                     29: ****************************************************************/
                     30:
                     31: /* Please send bug reports to David M. Gay (dmg at acm dot org,
                     32:  * with " at " changed at "@" and " dot " changed to ".").     */
                     33:
                     34: #include "gdtoaimp.h"
                     35:
                     36:  char*
                     37: #ifdef KR_headers
                     38: g_ffmt(buf, f, ndig, bufsize) char *buf; float *f; int ndig; unsigned bufsize;
                     39: #else
                     40: g_ffmt(char *buf, float *f, int ndig, unsigned bufsize)
                     41: #endif
                     42: {
                     43:        static FPI fpi = { 24, 1-127-24+1,  254-127-24+1, 1, 0 };
                     44:        char *b, *s, *se;
                     45:        ULong bits[1], *L, sign;
                     46:        int decpt, ex, i, mode;
                     47:
                     48:        if (ndig < 0)
                     49:                ndig = 0;
                     50:        if (bufsize < ndig + 10)
                     51:                return 0;
                     52:
                     53:        L = (ULong*)f;
                     54:        sign = L[0] & 0x80000000L;
                     55:        if ((L[0] & 0x7f800000) == 0x7f800000) {
                     56:                /* Infinity or NaN */
                     57:                if (L[0] & 0x7fffff) {
                     58:                        return strcp(buf, "NaN");
                     59:                        }
                     60:                b = buf;
                     61:                if (sign)
                     62:                        *b++ = '-';
                     63:                return strcp(b, "Infinity");
                     64:                }
                     65:        if (*f == 0.) {
                     66:                b = buf;
                     67: #ifndef IGNORE_ZERO_SIGN
                     68:                if (L[0] & 0x80000000L)
                     69:                        *b++ = '-';
                     70: #endif
                     71:                *b++ = '0';
                     72:                *b = 0;
                     73:                return b;
                     74:                }
                     75:        bits[0] = L[0] & 0x7fffff;
                     76:        if ( (ex = (L[0] >> 23) & 0xff) !=0)
                     77:                bits[0] |= 0x800000;
                     78:        else
                     79:                ex = 1;
                     80:        ex -= 0x7f + 23;
                     81:        mode = 2;
                     82:        if (ndig <= 0) {
                     83:                if (bufsize < 16)
                     84:                        return 0;
                     85:                mode = 0;
                     86:                }
                     87:        i = STRTOG_Normal;
                     88:        s = gdtoa(&fpi, ex, bits, &i, mode, ndig, &decpt, &se);
1.2     ! christos   89:        if (s == NULL)
        !            90:                return NULL;
1.1       kleink     91:        return g__fmt(buf, s, se, decpt, sign);
                     92:        }

CVSweb <webmaster@jp.NetBSD.org>