comparison tests/test-fprintf-posix.h @ 9938:9f8c455639fc

Fix rounding when a precision is given.
author Bruno Haible <bruno@clisp.org>
date Sat, 19 Apr 2008 17:26:36 +0200
parents bbbbbf4cd1c5
children b5e42ef33b49
comparison
equal deleted inserted replaced
9937:adf13947ae6c 9938:9f8c455639fc
1 /* Test of POSIX compatible vsprintf() and sprintf() functions. 1 /* Test of POSIX compatible vsprintf() and sprintf() functions.
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007-2008 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or 6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version. 7 (at your option) any later version.
63 my_fprintf (stdout, "%015f %d\n", 1234.0, 33, 44, 55); 63 my_fprintf (stdout, "%015f %d\n", 1234.0, 33, 44, 55);
64 64
65 /* Precision. */ 65 /* Precision. */
66 my_fprintf (stdout, "%.f %d\n", 1234.0, 33, 44, 55); 66 my_fprintf (stdout, "%.f %d\n", 1234.0, 33, 44, 55);
67 67
68 /* Precision with no rounding. */
69 my_fprintf (stdout, "%.2f %d\n", 999.95, 33, 44, 55);
70
71 /* Precision with rounding. */
72 my_fprintf (stdout, "%.2f %d\n", 999.996, 33, 44, 55);
73
68 /* A positive number. */ 74 /* A positive number. */
69 my_fprintf (stdout, "%Lf %d\n", 12.75L, 33, 44, 55); 75 my_fprintf (stdout, "%Lf %d\n", 12.75L, 33, 44, 55);
70 76
71 /* A larger positive number. */ 77 /* A larger positive number. */
72 my_fprintf (stdout, "%Lf %d\n", 1234567.0L, 33, 44, 55); 78 my_fprintf (stdout, "%Lf %d\n", 1234567.0L, 33, 44, 55);
80 /* FLAG_ZERO. */ 86 /* FLAG_ZERO. */
81 my_fprintf (stdout, "%015Lf %d\n", 1234.0L, 33, 44, 55); 87 my_fprintf (stdout, "%015Lf %d\n", 1234.0L, 33, 44, 55);
82 88
83 /* Precision. */ 89 /* Precision. */
84 my_fprintf (stdout, "%.Lf %d\n", 1234.0L, 33, 44, 55); 90 my_fprintf (stdout, "%.Lf %d\n", 1234.0L, 33, 44, 55);
91
92 /* Precision with no rounding. */
93 my_fprintf (stdout, "%.2Lf %d\n", 999.95L, 33, 44, 55);
94
95 /* Precision with rounding. */
96 my_fprintf (stdout, "%.2Lf %d\n", 999.996L, 33, 44, 55);
85 97
86 /* Test the support of the %F format directive. */ 98 /* Test the support of the %F format directive. */
87 99
88 /* A positive number. */ 100 /* A positive number. */
89 my_fprintf (stdout, "%F %d\n", 12.75, 33, 44, 55); 101 my_fprintf (stdout, "%F %d\n", 12.75, 33, 44, 55);
101 my_fprintf (stdout, "%015F %d\n", 1234.0, 33, 44, 55); 113 my_fprintf (stdout, "%015F %d\n", 1234.0, 33, 44, 55);
102 114
103 /* Precision. */ 115 /* Precision. */
104 my_fprintf (stdout, "%.F %d\n", 1234.0, 33, 44, 55); 116 my_fprintf (stdout, "%.F %d\n", 1234.0, 33, 44, 55);
105 117
118 /* Precision with no rounding. */
119 my_fprintf (stdout, "%.2F %d\n", 999.95, 33, 44, 55);
120
121 /* Precision with rounding. */
122 my_fprintf (stdout, "%.2F %d\n", 999.996, 33, 44, 55);
123
106 /* A positive number. */ 124 /* A positive number. */
107 my_fprintf (stdout, "%LF %d\n", 12.75L, 33, 44, 55); 125 my_fprintf (stdout, "%LF %d\n", 12.75L, 33, 44, 55);
108 126
109 /* A larger positive number. */ 127 /* A larger positive number. */
110 my_fprintf (stdout, "%LF %d\n", 1234567.0L, 33, 44, 55); 128 my_fprintf (stdout, "%LF %d\n", 1234567.0L, 33, 44, 55);
119 my_fprintf (stdout, "%015LF %d\n", 1234.0L, 33, 44, 55); 137 my_fprintf (stdout, "%015LF %d\n", 1234.0L, 33, 44, 55);
120 138
121 /* Precision. */ 139 /* Precision. */
122 my_fprintf (stdout, "%.LF %d\n", 1234.0L, 33, 44, 55); 140 my_fprintf (stdout, "%.LF %d\n", 1234.0L, 33, 44, 55);
123 141
142 /* Precision with no rounding. */
143 my_fprintf (stdout, "%.2LF %d\n", 999.95L, 33, 44, 55);
144
145 /* Precision with rounding. */
146 my_fprintf (stdout, "%.2LF %d\n", 999.996L, 33, 44, 55);
147
124 /* Test the support of the POSIX/XSI format strings with positions. */ 148 /* Test the support of the POSIX/XSI format strings with positions. */
125 149
126 my_fprintf (stdout, "%2$d %1$d\n", 33, 55); 150 my_fprintf (stdout, "%2$d %1$d\n", 33, 55);
127 } 151 }