1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2015 Free Software Foundation, Inc.
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
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 #include "math/decimal.h"
30 dump_scale (const struct decimal *low, const struct decimal *interval, int n_ticks)
33 struct decimal tick = *low;
34 for (i = 0; i <= n_ticks; ++i)
36 printf ("Tick %d: %s (%g)\n", i, decimal_to_string (&tick), decimal_to_double (&tick));
37 decimal_add (&tick, interval);
43 test_range (double low, double high)
46 struct decimal interval;
50 chart_get_scale (high, low,
51 &lower, &interval, &n_ticks);
54 assert (n_ticks < 12);
56 // dump_scale (&lower, &interval, n_ticks);
58 assert (decimal_to_double (&lower) <= low);
61 struct decimal l = lower;
62 decimal_add (&l, &interval);
63 assert (decimal_to_double (&l) > low);
67 struct decimal i = interval;
69 decimal_int_multiply (&i, n_ticks - 1);
71 decimal_add (&i, &lower);
73 /* i now contains the upper bound minus one tick */
74 assert (decimal_to_double (&i) < high);
76 decimal_add (&i, &interval);
78 assert (decimal_to_double (&i) >= high);
85 main (int argc, char **argv)
88 test_range (-0.2, 11);
89 test_range (-10, 0.2);
90 test_range (-10, -0.2);
92 test_range (102, 50030);
93 test_range (0.00102, 0.0050030);