167{
168 double scaled;
169 double axis_cells;
170
171 if (histo_cells_target <= 0 || histo_ndims <= 0)
172 return 1;
173
174 if (!(edge_ratio > 0.0) || !isfinite(edge_ratio))
175 return 1;
176
177 scaled = (double)histo_cells_target * (double)histo_ndims * edge_ratio;
178 if (!(scaled > 0.0) || !isfinite(scaled))
179 return 1;
180
181 axis_cells = pow(scaled, 1.0 / (double)histo_ndims);
182 if (!(axis_cells > 0.0) || !isfinite(axis_cells))
183 return 1;
184
185 if (axis_cells >= (double)INT_MAX)
186 return INT_MAX;
187
188 if (axis_cells <= 1.0)
189 return 1;
190
191 return (int)axis_cells;
192}