View source: R/generator-double.R
| gen_double | R Documentation |
At size zero, gen_double() draws only origin. The bounds expand linearly
from the origin to min and max, reaching the full interval at size 100.
Larger sizes use that same interval. Use gen_resize() to sample the full
range at every runner size. Within the current bounds, generation interpolates
one uniform draw from stats::runif(). This samples a finite-precision
approximation to a continuous uniform distribution, not all representable
doubles uniformly. Bounds are inclusive constraints; endpoints are not
guaranteed to be drawn. Use gen_choice() with constants to target them.
gen_double(min = -100, max = 100, origin = NULL)
min, max |
Finite scalar numeric bounds, with |
origin |
Finite scalar numeric shrink target within the bounds. |
Shrinking tries the origin, then the midpoint between the origin and the generated value, then successive midpoints approaching that value. For example, 8 with origin 0 has children 0, 4, 6, 7, 7.5, and so on. Each child follows the same rule. Candidates remain between the origin and their parent; iteration stops when rounding prevents further progress. Children are built only when visited. Values close to zero can require many steps to shrink through subnormal doubles, so the runner's evaluation budget still applies.
NA, NaN, and infinities are excluded. Add them explicitly with
gen_choice() or gen_element(). Branch weights control generation and
branch order controls shrinking; zero-weight branches are excluded from both.
An S7 generator with a double element prototype.
Haskell Hedgehog separates shrink origins from
size-dependent bounds
and uses fractional shrinking toward an origin.
The R Hedgehog manual
documents gen.unif() and mixtures with exceptional numeric values.
measurements <- gen_double(-10, 10)
gen_example(measurements, size = 100L)
# 80% finite draws; 5% each for NA, NaN, -Inf, and Inf.
numeric_values <- gen_choice(
measurements, gen_element(c(NA_real_, NaN, -Inf, Inf)),
prob = c(4, 1)
)
gen_example(gen_vector(numeric_values, max = 5L))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.