Subversion Repositories shark

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/* Project:     OSLib
2
 * Description: The OS Construction Kit
3
 * Date:                1.6.2000
4
 * Idea by:             Luca Abeni & Gerardo Lamastra
5
 *
6
 * OSLib is an SO project aimed at developing a common, easy-to-use
7
 * low-level infrastructure for developing OS kernels and Embedded
8
 * Applications; it partially derives from the HARTIK project but it
9
 * currently is independently developed.
10
 *
11
 * OSLib is distributed under GPL License, and some of its code has
12
 * been derived from the Linux kernel source; also some important
13
 * ideas come from studying the DJGPP go32 extender.
14
 *
15
 * We acknowledge the Linux Community, Free Software Foundation,
16
 * D.J. Delorie and all the other developers who believe in the
17
 * freedom of software and ideas.
18
 *
19
 * For legalese, check out the included GPL license.
20
 */
21
 
22
#include <ll/i386/stdlib.h>
23
#include <ll/i386/string.h>
24
#include <ll/i386/limits.h>
25
#include <ll/i386/float.h>
26
#include <ll/i386/mem.h>
27
#include <ll/stdarg.h>
28
#include <ll/ctype.h>
29
#include <ll/math.h>
30
#include "sprintf.h"
31
 
32
FILE(gcvt);
33
 
34
unsigned gcvt(double v,char *buffer,int width,int prec,int flag)
35
{
36
    double v_abs;
37
    int exponent;
38
    /* Manage Inf & NaN */
39
    if (isspecial(v,buffer)) return(strlen(buffer));
40
    /* Extract absolute value */
41
    if (v < 0.0) v_abs = -v;
42
    else v_abs = v;
43
    /* Zero check! */
44
    if (v_abs < DBL_MIN) {
45
        *buffer++ = '0';
46
        *buffer = 0;
47
        return(1);
48
    }
49
    exponent = 0;
50
    /* Evaluate exponent */
51
    if (v_abs < 1.0) {
52
        while (v_abs < 1) {
53
            v_abs *= 10.0;
54
            exponent--;
55
        }
56
    }
57
    else {
58
        while (v_abs >= 10.0) {
59
            v_abs /= 10.0;
60
            exponent++;
61
        }
62
    }
63
    /* Choose shortest format on exponent value */
64
    if (exponent > 7 || exponent < -7)
65
       return(ecvt(v,buffer,width,prec,flag));
66
    else return(fcvt(v,buffer,width,prec,flag));
67
}