+char *opt_set_floatval(const char *arg, float *f)
+{
+ double d;
+ char *err;
+
+ err = opt_set_doubleval(arg, &d);
+ if (err)
+ return err;
+
+ *f = d;
+
+ /*allow true infinity via --foo=INF, while avoiding isinf() from math.h
+ because it wasn't standard 25 years ago.*/
+ double inf = 1e300 * 1e300; /*direct 1e600 annoys -Woverflow*/
+ if ((d > FLT_MAX || d < -FLT_MAX) && d != inf && d != -inf)
+ return arg_bad("'%s' is out of range for a 32 bit float", arg);
+ if (d != 0 && *f == 0)
+ return arg_bad("'%s' is out of range (truncated to zero)", arg);
+
+ return NULL;
+}
+
+void opt_show_floatval(char buf[OPT_SHOW_LEN], const float *f)
+{
+ double d = *f;
+ opt_show_doubleval(buf, &d);
+}
+
+char *opt_set_doubleval(const char *arg, double *d)
+{
+ char *endp;
+
+ /* This is how the manpage says to do it. Yech. */
+ errno = 0;
+ /* Don't assume strtof */
+ *d = strtod(arg, &endp);
+ if (*endp || !arg[0])
+ return arg_bad("'%s' is not a number", arg);
+ if (errno)
+ return arg_bad("'%s' is out of range", arg);
+
+ return NULL;
+}
+
+void opt_show_doubleval(char buf[OPT_SHOW_LEN], const double *d)
+{
+ snprintf(buf, OPT_SHOW_LEN, "%f", *d);
+}
+