On Sat, Oct 21, 2017 at 05:04:44AM +0200, Theo Buehler wrote:
> > Found missing output given specific arg for reps, begin, end; need help.
> >
> > >How-To-Repeat:
> >
> > $ jot 259 101 360 > /tmp/a
> > $ jot 260 101 360 > /tmp/b
> > $ diff -u /tmp/{a,b}
> > --- /tmp/a Fri Oct 20 17:49:19 2017
> > +++ /tmp/b Fri Oct 20 17:49:30 2017
> > @@ -128,6 +128,7 @@
> > 228
> > 229
> > 230
> > +231
> > 232
> > 233
> > 234
>
> It's expected behavior.
>
> First note that jot prints as many numbers as requested by the first
> argument:
>
> $ jot 259 101 360 | wc -l
> 259
> $ jot 260 101 360 | wc -l
> 260
>
> Quoting from the 'Rounding and truncation' section of the manual:
>
> The jot utility uses double precision floating point arithmetic
> internally. Before printing a number, it is converted depending on the
> output format used.
>
> If no output format is specified or the output format is a floating point
> format (‘f’, ‘e’, ‘g’, ‘E’, or ‘G’), the value is rounded using the
> printf(3) function, taking into account the requested precision.
>
> You didn't request a precision (number of decimal digits to display) by
> giving a format string or a -p option, and you didn't specify a step
> size (no fourth argument).
>
> Therefore jot computes the step size as a floating point number by
>
> step = (end - begin) / (reps - 1)
>
> (In your examples, steps is approximately 1.004 and 1, respectively.)
>
> jot chooses the display precision as follows:
>
> -p precision Print only as many digits or characters of the data as
> indicated by the integer precision. In the absence of -p,
> the precision is the greater of the numbers begin and end.
> The -p option is overridden by whatever appears in a
> printf(3) conversion following -w.
>
> begin (101) and end (360) both have integer precision, so so jot
> displays the output by rounding to integer precision.
>
> If you print with higher precision, you see that it's a rounding issue:
>
> $ jot -p 3 259 101 360 | sed -n '128,132p'
> 228.492
> 229.496
> 230.500
> 231.504
> 232.508
>
> Without -p 3, all numbers up to the values 228.492 and 229.496 are
> rounded down, while from 230.500 onwards, the values are rounded up,
> resulting in the output 228, 229, 231, 232, therefore omitting 230.
Sorry, I was too quick in the end: since printf is used, 230.500 ends up
being rounded down, that's why 230 is printed and 231 is omitted in your
output.