@@ -165,15 +165,22 @@ step_type<T> step(T t) {
165165 return step_type<T>{t};
166166}
167167
168- /* *
169- Axis for equidistant intervals on the real line.
168+ /* * Axis for equidistant intervals on the real line.
169+
170+ The most common binning strategy. Very fast. Binning is a O(1) operation.
170171
171- The most common binning strategy. Very fast. Binning is a O(1) operation.
172+ If the axis has an overflow bin (the default), a value on the upper edge of the last
173+ bin is put in the overflow bin. The axis range represents a semi-open interval.
172174
173- @tparam Value input value type, must be floating point.
174- @tparam Transform builtin or user-defined transform type.
175- @tparam MetaData type to store meta data.
176- @tparam Options see boost::histogram::axis::option.
175+ If the overflow bin is deactivated, then a value on the upper edge of the last bin is
176+ still counted towards the last bin. The axis range represents a closed interval. This
177+ is the desired behavior for random numbers drawn from a bounded interval, which is
178+ usually closed.
179+
180+ @tparam Value input value type, must be floating point.
181+ @tparam Transform builtin or user-defined transform type.
182+ @tparam MetaData type to store meta data.
183+ @tparam Options see boost::histogram::axis::option.
177184 */
178185template <class Value , class Transform , class MetaData , class Options >
179186class regular : public iterator_mixin <regular<Value, Transform, MetaData, Options>>,
@@ -207,13 +214,13 @@ class regular : public iterator_mixin<regular<Value, Transform, MetaData, Option
207214 constexpr regular () = default;
208215
209216 /* * Construct n bins over real transformed range [start, stop).
210- *
211- * @param trans transform instance to use.
212- * @param n number of bins.
213- * @param start low edge of first bin.
214- * @param stop high edge of last bin.
215- * @param meta description of the axis (optional).
216- * @param options see boost::histogram::axis::option (optional).
217+
218+ @param trans transform instance to use.
219+ @param n number of bins.
220+ @param start low edge of first bin.
221+ @param stop high edge of last bin.
222+ @param meta description of the axis (optional).
223+ @param options see boost::histogram::axis::option (optional).
217224 */
218225 regular (transform_type trans, unsigned n, value_type start, value_type stop,
219226 metadata_type meta = {}, options_type options = {})
@@ -232,30 +239,30 @@ class regular : public iterator_mixin<regular<Value, Transform, MetaData, Option
232239 }
233240
234241 /* * Construct n bins over real range [start, stop).
235- *
236- * @param n number of bins.
237- * @param start low edge of first bin.
238- * @param stop high edge of last bin.
239- * @param meta description of the axis (optional).
240- * @param options see boost::histogram::axis::option (optional).
242+
243+ @param n number of bins.
244+ @param start low edge of first bin.
245+ @param stop high edge of last bin.
246+ @param meta description of the axis (optional).
247+ @param options see boost::histogram::axis::option (optional).
241248 */
242249 regular (unsigned n, value_type start, value_type stop, metadata_type meta = {},
243250 options_type options = {})
244251 : regular({}, n, start, stop, std::move(meta), options) {}
245252
246253 /* * Construct bins with the given step size over real transformed range
247- * [start, stop).
248- *
249- * @param trans transform instance to use.
250- * @param step width of a single bin.
251- * @param start low edge of first bin.
252- * @param stop upper limit of high edge of last bin (see below).
253- * @param meta description of the axis (optional).
254- * @param options see boost::histogram::axis::option (optional).
255- *
256- * The axis computes the number of bins as n = abs(stop - start) / step,
257- * rounded down. This means that stop is an upper limit to the actual value
258- * (start + n * step).
254+ [start, stop).
255+
256+ @param trans transform instance to use.
257+ @param step width of a single bin.
258+ @param start low edge of first bin.
259+ @param stop upper limit of high edge of last bin (see below).
260+ @param meta description of the axis (optional).
261+ @param options see boost::histogram::axis::option (optional).
262+
263+ The axis computes the number of bins as n = abs(stop - start) / step,
264+ rounded down. This means that stop is an upper limit to the actual value
265+ (start + n * step).
259266 */
260267 template <class T >
261268 regular (transform_type trans, step_type<T> step, value_type start, value_type stop,
@@ -267,16 +274,16 @@ class regular : public iterator_mixin<regular<Value, Transform, MetaData, Option
267274 std::move(meta), options) {}
268275
269276 /* * Construct bins with the given step size over real range [start, stop).
270- *
271- * @param step width of a single bin.
272- * @param start low edge of first bin.
273- * @param stop upper limit of high edge of last bin (see below).
274- * @param meta description of the axis (optional).
275- * @param options see boost::histogram::axis::option (optional).
276- *
277- * The axis computes the number of bins as n = abs(stop - start) / step,
278- * rounded down. This means that stop is an upper limit to the actual value
279- * (start + n * step).
277+
278+ @param step width of a single bin.
279+ @param start low edge of first bin.
280+ @param stop upper limit of high edge of last bin (see below).
281+ @param meta description of the axis (optional).
282+ @param options see boost::histogram::axis::option (optional).
283+
284+ The axis computes the number of bins as n = abs(stop - start) / step,
285+ rounded down. This means that stop is an upper limit to the actual value
286+ (start + n * step).
280287 */
281288 template <class T >
282289 regular (step_type<T> step, value_type start, value_type stop, metadata_type meta = {},
@@ -311,6 +318,8 @@ class regular : public iterator_mixin<regular<Value, Transform, MetaData, Option
311318 else
312319 return -1 ;
313320 }
321+ // upper edge of last bin is inclusive if overflow bin is not present
322+ if (!options_type::test (option::overflow) && z == 1 ) return size () - 1 ;
314323 }
315324 return size (); // also returned if x is NaN
316325 }
0 commit comments