Subversion Repositories wimsdev

Rev

Rev 7037 | Rev 7076 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7037 Rev 7038
Line 23... Line 23...
23
Using the original amount of digits used in "number" argument
23
Using the original amount of digits used in "number" argument
24
!exec scienceprint 123.445000e+23,-1 --> 1.23445000*10^25
24
!exec scienceprint 123.445000e+23,-1 --> 1.23445000*10^25
25
 
25
 
26
27/9/2013
26
27/9/2013
27
Correct rounding in stead of truncation...
27
Correct rounding in stead of truncation...
-
 
28
28/9/2013
-
 
29
minor issue:
-
 
30
small correction in roundoff routine when significance > 6 .... pow(10,7) may give problems when stored in (int) integer
28
 
31
 
29
*********************************************************************************
32
*********************************************************************************
30
 
33
 
31
WIMS usage:
34
WIMS usage:
32
sci_num = !exec scienceprint number,significance,type
35
sci_num = !exec scienceprint number,significance,type
Line 112... Line 115...
112
char *printscience(double value, int sig, int format , int cnt ,int size){
115
char *printscience(double value, int sig, int format , int cnt ,int size){
113
    static char *min[] = {"","m",MICRO,"n","p","f","a","z","y"};
116
    static char *min[] = {"","m",MICRO,"n","p","f","a","z","y"};
114
    static char *plus[] = {"","k", "M", "G", "T", "P", "E", "Z", "Y" };
117
    static char *plus[] = {"","k", "M", "G", "T", "P", "E", "Z", "Y" };
115
    static char *min_word[] = {"","milli","micro","nano","pico","femto","atto","zepto","yocto"};
118
    static char *min_word[] = {"","milli","micro","nano","pico","femto","atto","zepto","yocto"};
116
    static char *plus_word[] = {"","kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta" };
119
    static char *plus_word[] = {"","kilo", "mega", "giga", "tera", "peta", "exa", "zetta", "yotta" };
117
    char *sign = NULL;char *prefix = NULL;
120
    char *sign = NULL;char *prefix = NULL;int pm;int factor;
118
    int exponent10 = 0;
121
    int exponent10 = 0;
119
    int factor = pow(10,sig);
-
 
120
    int use_word = 0;if(format == 5){format = 3; use_word = 1;} /* switch to using words in stead of prefix  */
122
    int use_word = 0;if(format == 5){format = 3; use_word = 1;} /* switch to using words in stead of prefix  */
121
    if(value < 0.0) {sign = "-";value = -value;sig--;} else {sign = "";}    if( sig == -1 ){
123
    if(value < 0.0) {pm = -0.5; sign = "-";value = -value;} else {sign = ""; pm = 0.5;}    
-
 
124
    if( sig == -1 ){
122
     /*
125
     /*
123
     no significance truncations...just science notation 1234 -> 1.234*10^3
126
     no significance truncations...just science notation 1234 -> 1.234*10^3
124
     try (!) to use same amount of digits
127
     try (!) to use same amount of digits
125
     */
128
     */
126
        sig = size;
129
        sig = size;
Line 142... Line 145...
142
            exponent10--;
145
            exponent10--;
143
            /* need to set a limit to number of while loops ! */
146
            /* need to set a limit to number of while loops ! */
144
            if(exponent10 <-100){fprintf(stdout,"error : number too small (exponent < -100)\n");return 0;}
147
            if(exponent10 <-100){fprintf(stdout,"error : number too small (exponent < -100)\n");return 0;}
145
        }
148
        }
146
    }
149
    }
147
    /* 27/9/2013 avoid truncating and do normal rounding...grrr */
150
    /* 27/9/2013 avoid truncating and do rounding...but not with 7 significant digits*/
-
 
151
    if(sig > 6){factor = 100000;}else{factor = pow(10,sig+1);}
148
    value = (round(factor*value))/factor;
152
    value = (round(factor*value + (pm) ))/factor; /* pm = +/- 0.5 */
149
    if(format == 3 && ((exponent10 < PREFIX_START) || (exponent10 > PREFIX_END))){
153
    if(format == 3 && ((exponent10 < PREFIX_START) || (exponent10 > PREFIX_END))){
150
        format = 1; /* not in my list of prefixes ; print in html ! */
154
        format = 1; /* not in my list of prefixes ; print in html ! */
151
    }
155
    }
152
    sig = sig - 1; /* "%.*f" counts the "." */
156
    sig = sig - 1; /* "%.*f" counts the "." */
153
    if(cnt > 1){fprintf(stdout,",");}/* more than one conversion to do : make list */
157
    if(cnt > 1){fprintf(stdout,",");}/* more than one conversion to do : make list */