[BACK]Return to jot.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / jot

Diff for /src/usr.bin/jot/jot.c between version 1.26 and 1.27

version 1.26, 2015/10/09 01:37:07 version 1.27, 2016/01/10 01:15:52
Line 40 
Line 40 
 #include <stdbool.h>  #include <stdbool.h>
 #include <ctype.h>  #include <ctype.h>
 #include <limits.h>  #include <limits.h>
   #include <math.h>
   #include <stdint.h>
 #include <stdio.h>  #include <stdio.h>
 #include <stdlib.h>  #include <stdlib.h>
 #include <string.h>  #include <string.h>
Line 268 
Line 270 
         if (reps == 0)          if (reps == 0)
                 infinity = true;                  infinity = true;
         if (randomize) {          if (randomize) {
                 x = (ender - begin) * (ender > begin ? 1 : -1);                  bool            use_unif;
                   uint32_t        pow10 = 1;
                   uint32_t        uintx = 0; /* Initialized to make gcc happy. */
   
                   if (prec > 9)   /* pow(10, prec) > UINT32_MAX */
                           errx(1, "requested precision too large");
   
                   while (prec-- > 0)
                           pow10 *= 10;
   
                   if (ender < begin) {
                           x = begin;
                           begin = ender;
                           ender = x;
                   }
                   x = ender - begin;
   
                   /*
                    * If pow10 * (ender - begin) is an integer, use
                    * arc4random_uniform().
                    */
                   use_unif = fmod(pow10 * (ender - begin), 1) == 0;
                   if (use_unif) {
                           uintx = pow10 * (ender - begin);
                           if (uintx >= UINT32_MAX)
                                   errx(1, "requested range too large");
                           uintx++;
                   }
   
                 for (i = 1; i <= reps || infinity; i++) {                  for (i = 1; i <= reps || infinity; i++) {
                         double v;                          double v;
                         y = arc4random() / ((double)0xffffffff + 1);  
                         v = y * x + begin;                          if (use_unif) {
                                   y = arc4random_uniform(uintx) / (double)pow10;
                                   v = y + begin;
                           } else {
                                   y = arc4random() / ((double)0xffffffff + 1);
                                   v = y * x + begin;
                           }
                         if (putdata(v, reps == i && !infinity))                          if (putdata(v, reps == i && !infinity))
                                 errx(1, "range error in conversion: %f", v);                                  errx(1, "range error in conversion: %f", v);
                 }                  }

Legend:
Removed from v.1.26  
changed lines
  Added in v.1.27