75
75
attribute_hidden
76
76
double R_pretty (double * lo , double * up , int * ndiv , int min_n ,
77
77
double shrink_sml ,
78
- const double high_u_fact [], // = (h, h5, f_min) below
78
+ const double high_u_fact [], // = (h, h5, f_min) below
79
79
int eps_correction , int return_bounds )
80
80
{
81
81
/* From version 0.65 on, we had rounding_eps := 1e-5, before, r..eps = 0
@@ -110,7 +110,7 @@ double R_pretty(double *lo, double *up, int *ndiv, int min_n,
110
110
#ifdef DEBUGpr
111
111
REprintf ("R_pretty(lo=%g,up=%g,ndiv=%d,min_n=%d,shrink=%g,high_u=(%g,%g,%g),eps=%d,bnds=%d)"
112
112
"\n\t => dx=%g; i_small:%s. ==> first cell=%g\n" ,
113
- lo_ , up_ , * ndiv , min_n , shrink_sml , h , h5 , min_f ,
113
+ lo_ , up_ , * ndiv , min_n , shrink_sml , h , h5 , f_min ,
114
114
eps_correction , return_bounds ,
115
115
dx , i_small ? "TRUE" : "F" , cell );
116
116
#endif
@@ -142,11 +142,12 @@ double R_pretty(double *lo, double *up, int *ndiv, int min_n,
142
142
if (subsmall == 0. ) // subnormals underflowing to zero (not yet seen!)
143
143
subsmall = DBL_MIN ;
144
144
if (cell < subsmall ) { // possibly subnormal
145
- warning (_ ("R_pretty(): very small range 'cell'=%g, corrected to %g" ),
145
+ if (cell > 0 )
146
+ warning (_ ("R_pretty(): very small range 'cell'=%.3g, increased to %g" ),
146
147
cell , subsmall );
147
148
cell = subsmall ;
148
149
} else if (cell > DBL_MAX /MAX_F ) {
149
- warning (_ ("R_pretty(): very large range 'cell'=%g, corrected to %g" ),
150
+ warning (_ ("R_pretty(): very large range 'cell'=%.3g, decreased to %g" ),
150
151
cell , DBL_MAX /MAX_F );
151
152
cell = DBL_MAX /MAX_F ;
152
153
}
@@ -181,9 +182,18 @@ double R_pretty(double *lo, double *up, int *ndiv, int min_n,
181
182
cell , base , unit , ns , nu );
182
183
#endif
183
184
if (eps_correction && (eps_correction > 1 || !i_small )) {
184
- // FIXME?: assumes 0 <= lo <= up (what if lo <= up < 0 ?)
185
- if (lo_ != 0. ) * lo *= (1 - DBL_EPSILON ); else * lo = - DBL_MIN ;
186
- if (up_ != 0. ) * up *= (1 + DBL_EPSILON ); else * up = + DBL_MIN ;
185
+ #define E_ DBL_EPSILON
186
+ const double D_max = DBL_MAX * (1. - ldexp (E_ , -1 ));
187
+ /* move *lo to the left, assuming <subnorm>*(1-E_) does not underflow to 0 : */
188
+ if (lo_ < 0. ) * lo *= (1 + E_ ); else if (lo_ > 0 ) * lo *= (1 - E_ ); else * lo = - fmin2 (unit , DBL_MIN );
189
+ /* and *up to the right : */
190
+ if (up_ < 0. ) * up *= (1 - E_ ); else if (up_ > 0. ) {
191
+ if (up_ < D_max ) * up *= (1 + E_ );} else * up = + fmin2 (unit , DBL_MIN );
192
+ #undef E_
193
+ #ifdef DEBUGpr
194
+ REprintf (" eps_correction (assuming lo=%g <= %g=up): new *lo=%g, *up=%g\n" ,
195
+ lo_ , up_ , * lo , * up );
196
+ #endif
187
197
}
188
198
189
199
#ifdef DEBUGpr
@@ -194,7 +204,7 @@ double R_pretty(double *lo, double *up, int *ndiv, int min_n,
194
204
195
205
#ifdef DEBUGpr
196
206
if (!R_FINITE (ns * unit ))
197
- REprintf ("\t infinite ( ns=%.0f)*(unit=%g) ==> ns++\n" , ns , unit );
207
+ REprintf ("\t while(!finite(( ns=%.0f)*(unit=%g))) ns++\n" , ns , unit );
198
208
#endif
199
209
while (!R_FINITE (ns * unit )) ns ++ ;
200
210
@@ -207,7 +217,7 @@ double R_pretty(double *lo, double *up, int *ndiv, int min_n,
207
217
208
218
#ifdef DEBUGpr
209
219
if (!R_FINITE (nu * unit ))
210
- REprintf ("\t infinite ( nu=%.0f)*(unit=%g) ==> nu--\n" , nu , unit );
220
+ REprintf ("\t while(!finite(( nu=%.0f)*(unit=%g)) nu--\n" , nu , unit );
211
221
#endif
212
222
while (!R_FINITE (nu * unit )) nu -- ;
213
223
@@ -246,7 +256,7 @@ double R_pretty(double *lo, double *up, int *ndiv, int min_n,
246
256
if (ns * unit < * lo ) * lo = ns * unit ;
247
257
if (nu * unit > * up ) * up = nu * unit ;
248
258
#endif
249
- } else { // used in graphics GEpretty (), hence grid::grid.pretty()
259
+ } else { // used in graphics GEPretty (), hence grid::grid.pretty()
250
260
* lo = ns ;
251
261
* up = nu ;
252
262
}
0 commit comments