Changeset 82d062d8 in mainline
- Timestamp:
- 2012-10-31T21:03:03Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f220e25
- Parents:
- 34b9299
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/print/print6.c
r34b9299 r82d062d8 1 /* 2 * Copyright (c) 2012 Adam Hraska 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * - Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * - Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * - The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 1 29 #include <stdio.h> 2 30 #include <unistd.h> … … 4 32 5 33 #include <str.h> 6 7 8 9 34 10 35 const char *test_print6(void) … … 28 53 { 0.099999999999999999, "%g", "0.1", 0 }, 29 54 30 /* gcc and msvc convert "3.4567e-317" to different binary doubles. */ 55 /* 56 * gcc and msvc convert "3.4567e-317" to different binary 57 * doubles. 58 */ 31 59 { 3.4567e-317, "%g", "3.4567e-317", "3.456998e-317" }, 32 60 { 3.4567e-318, "%g", "3.4567e-318", 0 }, … … 56 84 57 85 /* full padding */ 58 { 1e-1, "%+010.3e", "+1.000e-01", 0 }, /* __PRINTF_FLAG_SHOWPLUS | __PRINTF_FLAG_ZEROPADDED */ 86 87 /* __PRINTF_FLAG_SHOWPLUS | __PRINTF_FLAG_ZEROPADDED */ 88 { 1e-1, "%+010.3e", "+1.000e-01", 0 }, 59 89 { 1e-1, "%+10.3e", "+1.000e-01", 0 }, 60 { 1e-1, "%+-10.3e", "+1.000e-01", 0 }, /* __PRINTF_FLAG_SHOWPLUS | __PRINTF_FLAG_LEFTALIGNED */ 90 /* __PRINTF_FLAG_SHOWPLUS | __PRINTF_FLAG_LEFTALIGNED */ 91 { 1e-1, "%+-10.3e", "+1.000e-01", 0 }, 61 92 62 93 /* padding */ 63 { 1e-1, "%+010.2e", "+01.00e-01", 0 }, /* __PRINTF_FLAG_SHOWPLUS | __PRINTF_FLAG_ZEROPADDED */ 94 95 /* __PRINTF_FLAG_SHOWPLUS | __PRINTF_FLAG_ZEROPADDED */ 96 { 1e-1, "%+010.2e", "+01.00e-01", 0 }, 64 97 { 1e-1, "%+10.2e", " +1.00e-01", 0 }, 65 { 1e-1, "%+-10.2e", "+1.00e-01 ", 0 }, /* __PRINTF_FLAG_SHOWPLUS | __PRINTF_FLAG_LEFTALIGNED */ 66 67 { 1e-1, "% 010.2e", " 01.00e-01", 0 }, /* __PRINTF_FLAG_SPACESIGN | __PRINTF_FLAG_ZEROPADDED */ 68 { 1e-1, "%010.2e", "001.00e-01", 0 }, /* __PRINTF_FLAG_ZEROPADDED */ 69 { 1e-1, "% 10.2e", " 1.00e-01", 0 }, /* __PRINTF_FLAG_SPACESIGN */ 98 /* __PRINTF_FLAG_SHOWPLUS | __PRINTF_FLAG_LEFTALIGNED */ 99 { 1e-1, "%+-10.2e", "+1.00e-01 ", 0 }, 100 /* __PRINTF_FLAG_SPACESIGN | __PRINTF_FLAG_ZEROPADDED */ 101 { 1e-1, "% 010.2e", " 01.00e-01", 0 }, 102 /* __PRINTF_FLAG_ZEROPADDED */ 103 { 1e-1, "%010.2e", "001.00e-01", 0 }, 104 /* __PRINTF_FLAG_SPACESIGN */ 105 { 1e-1, "% 10.2e", " 1.00e-01", 0 }, 70 106 { 1e-1, "%10.2e", " 1.00e-01", 0 }, 71 107 72 108 /* padding fractionals */ 73 { 1.08e29, "%+010.3e", "+1.080e+29", 0 }, /* __PRINTF_FLAG_SHOWPLUS | __PRINTF_FLAG_ZEROPADDED */ 109 110 /* __PRINTF_FLAG_SHOWPLUS | __PRINTF_FLAG_ZEROPADDED */ 111 { 1.08e29, "%+010.3e", "+1.080e+29", 0 }, 74 112 { 1.08e29, "%+10.3e", "+1.080e+29", 0 }, 75 { 1.08e29, "%+011.2e", "+001.08e+29", 0 }, /* __PRINTF_FLAG_SHOWPLUS | __PRINTF_FLAG_ZEROPADDED */ 113 /* __PRINTF_FLAG_SHOWPLUS | __PRINTF_FLAG_ZEROPADDED */ 114 { 1.08e29, "%+011.2e", "+001.08e+29", 0 }, 76 115 { 1.085e29, "%11.2e", " 1.09e+29", 0 }, 77 116 78 117 /* rounding */ 118 79 119 { 1.345e2, "%+10.2e", " +1.35e+02", 0 }, 80 120 { 9.995e2, "%+10.2e", " +1.00e+03", 0 }, 81 121 { -9.99499999e2, "%10.2e", " -9.99e+02", 0 }, 82 122 { -9.99499999e2, "%10.0e", " -1e+03", 0 }, 83 { -9.99499999e2, "%#10.0e", " -1.e+03", 0 }, /* __PRINTF_FLAG_DECIMALPT */ 84 { -1.2345006789e+231, "%#10.10e", "-1.2345006789e+231", 0 }, /* __PRINTF_FLAG_DECIMALPT */ 85 { -1.23450067995e+231, "%#10.10e", "-1.2345006800e+231", 0 }, /* __PRINTF_FLAG_DECIMALPT */ 123 /* __PRINTF_FLAG_DECIMALPT */ 124 { -9.99499999e2, "%#10.0e", " -1.e+03", 0 }, 125 /* __PRINTF_FLAG_DECIMALPT */ 126 { -1.2345006789e+231, "%#10.10e", "-1.2345006789e+231", 0 }, 127 /* __PRINTF_FLAG_DECIMALPT */ 128 { -1.23450067995e+231, "%#10.10e", "-1.2345006800e+231", 0 }, 86 129 87 130 /* special */ 131 88 132 { 1e300 * 1e300, "%10.5e", " inf", 0 }, 89 133 { -1.0 /(1e300 * 1e300), "%10.2e", " -0.00e+00", 0 }, 90 { 1e300 * 1e300, "%10.5E", " INF", 0 }, /* __PRINTF_FLAG_BIGCHARS */ 91 { -1.0 /(1e300 * 1e300), "%10.2E", " -0.00E+00", 0 }, /* __PRINTF_FLAG_BIGCHARS */ 134 /* __PRINTF_FLAG_BIGCHARS */ 135 { 1e300 * 1e300, "%10.5E", " INF", 0 }, 136 /* __PRINTF_FLAG_BIGCHARS */ 137 { -1.0 /(1e300 * 1e300), "%10.2E", " -0.00E+00", 0 }, 92 138 93 139 /* … … 96 142 97 143 /* padding */ 98 { 1e-1, "% 010.3f", " 00000.100", 0 }, /* __PRINTF_FLAG_SPACESIGN | __PRINTF_FLAG_ZEROPADDED */ 99 { 1e-1, "% 0-10.3f", " 0.100 ", 0 }, /* __PRINTF_FLAG_SPACESIGN | __PRINTF_FLAG_ZEROPADDED | __PRINTF_FLAG_LEFTALIGNED */ 100 { 1e-1, "% 010.3f", " 00000.100", 0 }, /* __PRINTF_FLAG_SPACESIGN | __PRINTF_FLAG_ZEROPADDED */ 144 145 /* __PRINTF_FLAG_SPACESIGN | __PRINTF_FLAG_ZEROPADDED */ 146 { 1e-1, "% 010.3f", " 00000.100", 0 }, 147 /* 148 * __PRINTF_FLAG_SPACESIGN | __PRINTF_FLAG_ZEROPADDED | 149 * __PRINTF_FLAG_LEFTALIGNED 150 */ 151 { 1e-1, "% 0-10.3f", " 0.100 ", 0 }, 152 /* __PRINTF_FLAG_SPACESIGN | __PRINTF_FLAG_ZEROPADDED */ 153 { 1e-1, "% 010.3f", " 00000.100", 0 }, 101 154 { 1e-1, "%10.3f", " 0.100", 0 }, 102 155 103 156 /* rounding */ 157 104 158 { -0.0, "%10.0f", " -0", 0 }, 105 159 { -0.099, "%+10.3f", " -0.099", 0 }, … … 111 165 { 0.1, "%+10.6f", " +0.100000", 0 }, 112 166 113 /* The compiler will go for closer 0.10..055 instead of 0.09..917 */ 167 /* 168 * The compiler will go for closer 0.10..055 instead of 169 * 0.09..917 170 */ 114 171 { 0.1, "%+10.20f", "+0.10000000000000000550", 0 }, 115 172 /* Next closest to 0.1 */ 116 { 0.0999999999999999917, "%+10.20f", "+0.09999999999999999170", 0 }, 117 { 0.0999999999999999917, "%+10f", " +0.100000", 0 }, 118 { 0.0999999999999998945, "%10.20f", "0.09999999999999989450", 0 }, 119 173 { 0.0999999999999999917, "%+10.20f", "+0.09999999999999999170", 174 0 }, 175 { 0.0999999999999999917, "%+10f", " +0.100000", 0 }, 176 { 0.0999999999999998945, "%10.20f", "0.09999999999999989450", 177 0 }, 120 178 }; 121 179 … … 125 183 char buf[256 + 1] = { 0 }; 126 184 127 TPRINTF("Test printing of floating point numbers via printf(\"%%f\"):\n"); 185 TPRINTF("Test printing of floating point numbers via " 186 "printf(\"%%f\"):\n"); 128 187 129 188 for (int i = 0; i < patterns_len; ++i) { … … 131 190 snprintf(buf, buf_size, pat[i].fmt, pat[i].val); 132 191 133 if (0 == str_cmp(buf, pat[i].exp_str)) { 134 TPRINTF("ok: %s |%s| == |%s|\n", pat[i].fmt, buf, pat[i].exp_str); 192 if (!str_cmp(buf, pat[i].exp_str)) { 193 TPRINTF("ok: %s |%s| == |%s|\n", 194 pat[i].fmt, buf, pat[i].exp_str); 135 195 } else { 136 if (pat[i].warn_str && 0 == str_cmp(buf, pat[i].warn_str)) { 137 TPRINTF("warn: %s |%s| != |%s|\n", pat[i].fmt, buf, pat[i].exp_str); 196 if (pat[i].warn_str && !str_cmp(buf, pat[i].warn_str)) { 197 TPRINTF("warn: %s |%s| != |%s|\n", 198 pat[i].fmt, buf, pat[i].exp_str); 138 199 } else { 139 200 ++failed; 140 TPRINTF("ERR: %s |%s| != |%s|\n", pat[i].fmt, buf, pat[i].exp_str); 201 TPRINTF("ERR: %s |%s| != |%s|\n", 202 pat[i].fmt, buf, pat[i].exp_str); 141 203 } 142 204 } -
uspace/lib/c/generic/double_to_str.c
r34b9299 r82d062d8 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 #include <double_to_str.h> 29 30 -
uspace/lib/c/generic/ieee_double.c
r34b9299 r82d062d8 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 #include <ieee_double.h> 29 30 -
uspace/lib/c/generic/power_of_ten.c
r34b9299 r82d062d8 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 #include "private/power_of_ten.h" 29 30 -
uspace/lib/c/generic/private/power_of_ten.h
r34b9299 r82d062d8 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 #ifndef POWER_OF_TEN_H_ 29 30 #define POWER_OF_TEN_H_ … … 32 33 struct fp_num_t_tag; 33 34 34 35 void get_power_of_ten(int binary_exp, struct fp_num_t_tag *power_of_10, 36 int *decimal_exp); 37 35 extern void get_power_of_ten(int, struct fp_num_t_tag *, int *); 38 36 39 37 #endif -
uspace/lib/c/include/double_to_str.h
r34b9299 r82d062d8 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 #ifndef DOUBLE_TO_STR_H_ 29 30 #define DOUBLE_TO_STR_H_ … … 45 46 #define MAX_DOUBLE_STR_BUF_SIZE 21 46 47 47 48 48 /* Fwd decl.*/ 49 49 struct ieee_double_t_tag; 50 50 51 52 int double_to_short_str(struct ieee_double_t_tag val, char *buf, size_t buf_size, 53 int *dec_exponent); 54 55 int double_to_fixed_str(struct ieee_double_t_tag ieee_val, int signif_d_cnt, 56 int frac_d_cnt, char *buf, size_t buf_size, int *dec_exponent); 57 51 extern int double_to_short_str(struct ieee_double_t_tag, char *, size_t, int *); 52 extern int double_to_fixed_str(struct ieee_double_t_tag, int, int, char *, 53 size_t, int *); 58 54 59 55 #endif -
uspace/lib/c/include/ieee_double.h
r34b9299 r82d062d8 26 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 27 */ 28 28 29 #ifndef IEEE_DOUBLE_H_ 29 30 #define IEEE_DOUBLE_H_ … … 31 32 #include <stdint.h> 32 33 #include <bool.h> 33 34 34 35 35 /** Represents a non-negative floating point number: significand * 2^exponent */ … … 40 40 int exponent; 41 41 } fp_num_t; 42 43 42 44 43 /** Double number description according to IEEE 754. */ … … 66 65 } ieee_double_t; 67 66 68 69 ieee_double_t extract_ieee_double(double val); 67 extern ieee_double_t extract_ieee_double(double); 70 68 71 69 #endif
Note:
See TracChangeset
for help on using the changeset viewer.