- struct decimal clbound = low;
- struct decimal cubound = high;
- struct decimal candidate;
- decimal_init (&candidate, standard_tick[i], expd);
-
- decimal_divide (&clbound, &candidate);
- int fl = decimal_floor (&clbound);
- decimal_int_multiply (&candidate, fl);
- clbound = candidate;
-
-
- decimal_init (&candidate, standard_tick[i], expd);
- decimal_divide (&cubound, &candidate);
- int fu = decimal_ceil (&cubound);
- decimal_int_multiply (&candidate, fu);
-
- cubound = candidate;
-
- decimal_init (&candidate, standard_tick[i], expd);
- decimal_subtract (&cubound, &clbound);
- decimal_divide (&cubound, &candidate);
-
-
- ord_t n_int = decimal_floor (&cubound);
-
- /* We prefer to have between 5 and 10 tick marks on a scale */
- double f = 1 - exp (-0.2 * fabs (n_int - 7.5) / 7.5);
-
- if (f < fitness)
- {
- fitness = f;
- *lower = clbound;
- *interval = candidate;
- *n_ticks = n_int;
- }
+ double cinterval = standard_tick[i] * pow(10.0,logrange-1);
+ double clower = floor(low/cinterval) * cinterval;
+ int cnticks = ceil((high - clower) / cinterval)-1;
+ double cfitness = fabs(7.5 - cnticks);
+
+ if (cfitness < fitness) {
+ fitness = cfitness;
+ *lower = clower;
+ *interval = cinterval;
+ *n_ticks = cnticks;
+ }