Rev 7111 | Rev 12258 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7111 | Rev 7648 | ||
---|---|---|---|
Line 5... | Line 5... | ||
5 | * This source code file, and compiled objects derived from it, * |
5 | * This source code file, and compiled objects derived from it, * |
6 | * can be used and distributed without restriction, including for commercial use * |
6 | * can be used and distributed without restriction, including for commercial use * |
7 | * No warrenty whatsoever * |
7 | * No warrenty whatsoever * |
8 | ********************************************************************************* |
8 | ********************************************************************************* |
9 | 9 | ||
- | 10 | WIMS usage: |
|
- | 11 | sci_num = !exec scienceprint number,significance,type |
|
- | 12 | ||
- | 13 | number: a number (like 12345 123.45*10^2 123.45E+02) |
|
- | 14 | significance : desired precision (if significance= -1 : "science notation" in name amount of digits) |
|
- | 15 | type (optional args): calc = 0 / html = 1 / latex = 2 / prefix = 3 / mathml = 4 |
|
- | 16 | ||
- | 17 | default : calc notation : 120000,3 -> 1.20*10^5 |
|
- | 18 | type = 0 : calc notation : 120000,3,0 -> 1.20*10^5 |
|
- | 19 | type = 1 : html notation : 120000,3,1 -> 1.20×10<sup>5</sup> |
|
- | 20 | type = 2 : latex notation : 120000,3,2 -> 1.20 \times 10^{5} |
|
- | 21 | type = 3 : prefix-notation : 120000,3,3 -> 120.0 k |
|
- | 22 | type = 3 : if -24 > prefix > 24 -> type = 1 (html) |
|
- | 23 | type = 4 : mathml notation |
|
- | 24 | type = 5 : prefix-notation with words (nano,mega,giga...etc) :120000,3,3 -> 120.0 kilo |
|
- | 25 | ||
- | 26 | multiple conversion: use space between arguments |
|
- | 27 | scienceprint 120000,4 122900,5 120036,6,3 --> 120.0*10^3,122.90*10^3,120.036 k |
|
- | 28 | ||
- | 29 | ||
- | 30 | ********************************************************************************* |
|
10 | 16/10/2013 |
31 | 16/10/2013 |
11 | corrected roundoff in case "significance=-1" changed 'factor' from 'int' to 'float'...there must be a better way to do this... |
32 | corrected roundoff in case "significance=-1" changed 'factor' from 'int' to 'float'...there must be a better way to do this... |
12 | But in numbers > 1000000000000000 there is still a problem, so take care (!) |
33 | But in numbers > 1000000000000000 there is still a problem, so take care (!) |
13 | when there are more than 15 digits in the number (this may vary depending on system / implementations, I guess) |
34 | when there are more than 15 digits in the number (this may vary depending on system / implementations, I guess) |
14 | ./scienceprint 901234567890123 ,-1,0 --> 9.01234567890123*10^14 |
35 | ./scienceprint 901234567890123 ,-1,0 --> 9.01234567890123*10^14 |
15 | ./scienceprint 9012345678901234 ,-1,0 --> 9.012345678901236*10^15 |
36 | ./scienceprint 9012345678901234 ,-1,0 --> 9.012345678901236*10^15 |
16 | ./scienceprint 901234567890123*10^70 ,-1,0 --> 9.01234567890123*10^84 |
37 | ./scienceprint 901234567890123*10^70 ,-1,0 --> 9.01234567890123*10^84 |
17 | ./scienceprint 9012345678901234*10^70,-1,0 --> 9.012345678901227*10^85 |
38 | ./scienceprint 9012345678901234*10^70,-1,0 --> 9.012345678901227*10^85 |
18 | - | ||
- | 39 | ********************************************************************************* |
|
19 | 28/9/2013 |
40 | 28/9/2013 |
20 | minor issue: |
41 | minor issue: |
- | 42 | Added type = 5 : prefix-notation with words (nano,mega,giga...etc) |
|
21 | small correction in roundoff routine when significance > 6 .... pow(10,7) may give problems when stored in (int) integer |
43 | small correction in roundoff routine when significance > 6 .... pow(10,7) may give problems when stored in (int) integer |
22 | - | ||
- | 44 | ********************************************************************************* |
|
23 | 27/9/2013 |
45 | 27/9/2013 |
24 | Correct rounding in stead of truncation... |
46 | Correct rounding in stead of truncation... |
25 | - | ||
- | 47 | ********************************************************************************* |
|
26 | 18/10/2012 : |
48 | 18/10/2012 : |
27 | Added Mathml output |
49 | Added Mathml output |
28 | Added option significance=-1 |
50 | Added option significance=-1 |
29 | To be used when there is no significance known ; just tries to print the number in science notation |
51 | To be used when there is no significance known ; just tries to print the number in science notation |
30 | Using the original amount of digits used in "number" argument |
52 | Using the original amount of digits used in "number" argument |
31 | !exec scienceprint 123.445000e+23,-1 --> 1.23445000*10^25 |
53 | !exec scienceprint 123.445000e+23,-1 --> 1.23445000*10^25 |
32 | - | ||
- | 54 | ********************************************************************************* |
|
33 | 12/11/2012 |
55 | 12/11/2012 |
34 | Added support for numbers like 12345*10^12 |
56 | Added support for numbers like 12345*10^12 |
35 | 12345*10^12 --> 12345E12 ---> 1.2345*10^16 |
57 | 12345*10^12 --> 12345E12 ---> 1.2345*10^16 |
36 | - | ||
- | 58 | ********************************************************************************* |
|
37 | 20/6/2012 |
59 | 20/6/2012 |
38 | Corrected significance flaw when using prefixes |
60 | Corrected significance flaw when using prefixes |
39 | Simplified routines |
61 | Simplified routines |
40 | Added type = 5 : prefix-notation with words (nano,mega,giga...etc) |
- | |
41 | - | ||
42 | - | ||
43 | - | ||
44 | - | ||
45 | - | ||
46 | ********************************************************************************* |
- | |
47 | - | ||
48 | WIMS usage: |
- | |
49 | sci_num = !exec scienceprint number,significance,type |
- | |
50 | - | ||
51 | number: a number |
- | |
52 | significance : desired precision |
- | |
53 | type (optional args): calc = 0 / html = 1 / latex = 2 / prefix = 3 / mathml = 4 |
- | |
54 | - | ||
55 | default : calc notation : 120000,3 -> 1.20*10^5 |
- | |
56 | type = 0 : calc notation : 120000,3,0 -> 1.20*10^5 |
- | |
57 | type = 1 : html notation : 120000,3,1 -> 1.20×10<sup>5</sup> |
- | |
58 | type = 2 : latex notation : 120000,3,2 -> 1.20 \times 10^{5} |
- | |
59 | type = 3 : prefix-notation : 120000,3,3 -> 120.0 k |
- | |
60 | type = 3 : if -24 > prefix > 24 -> type = 1 (html) |
- | |
61 | type = 4 : mathml notation |
- | |
62 | - | ||
63 | multiple conversion: use space between arguments |
- | |
64 | scienceprint 120000,4 122900,5 120036,6,3 --> 120.0*10^3,122.90*10^3,120.036 k |
- | |
65 | - | ||
66 | 24 yotta Y |
62 | 24 yotta Y |
67 | 21 zetta Z |
63 | 21 zetta Z |
68 | 18 exa E |
64 | 18 exa E |
69 | 15 peta P |
65 | 15 peta P |
70 | 12 tera T |
66 | 12 tera T |
71 | 9 giga G |
67 | 9 giga G |
72 | 6 mega M |
68 | 6 mega M |
73 | 3 kilo k |
69 | 3 kilo k |
74 | - | ||
75 | 2 hecto h |
70 | 2 hecto h |
76 | 1 deca da |
71 | 1 deca da |
77 | -1 deci d |
72 | -1 deci d |
78 | -2 centi c |
73 | -2 centi c |
79 | - | ||
80 | -3 milli m |
74 | -3 milli m |
81 | -6 micro µ |
75 | -6 micro µ |
82 | -9 nano n |
76 | -9 nano n |
83 | -12 pico p |
77 | -12 pico p |
84 | -15 femto f |
78 | -15 femto f |
85 | -18 atto a |
79 | -18 atto a |
86 | -21 zepto z |
80 | -21 zepto z |
87 | -24 yocto y |
81 | -24 yocto y |
88 | - | ||
89 | */ |
82 | */ |
90 | - | ||
91 | #include <stdio.h> |
83 | #include <stdio.h> |
92 | #include <math.h> |
84 | #include <math.h> |
93 | #include <string.h> |
85 | #include <string.h> |
94 | #include <stdlib.h> |
86 | #include <stdlib.h> |
95 | #define MICRO "µ" |
87 | #define MICRO "µ" |