int main(void) { d_type *dptr; for (dptr = strtods; dptr->line; dptr++) { fprintf(stdout, "strtod32(\"%s\",NULL) == %Hf\n ", dptr->input, strtod32(dptr->input, NULL)); _VC_P(__FILE__,dptr->line,dptr->d32,strtod32(dptr->input,NULL), "%Hf"); fprintf(stdout, "strtod64(\"%s\",NULL) == %Df\n ", dptr->input, strtod64(dptr->input, NULL)); _VC_P(__FILE__,dptr->line,dptr->d64, strtod64(dptr->input,NULL), "%Df"); fprintf(stdout, "strtod128(\"%s\",NULL) == %DDf\n ", dptr->input, strtod128(dptr->input, NULL)); _VC_P(__FILE__,dptr->line,dptr->d128, strtod128(dptr->input,NULL), "%DDf"); } d_nan_type *dnanptr; for (dnanptr = strtods_nan; dnanptr->line; dnanptr++) { _DC_P(__FILE__,dnanptr->line,dnanptr->d32,strtod32(dnanptr->input,NULL)); _DC_P(__FILE__,dnanptr->line,dnanptr->d64, strtod64(dnanptr->input,NULL)); _DC_P(__FILE__,dnanptr->line,dnanptr->d128, strtod128(dnanptr->input,NULL)); } _REPORT(); /* fail comes from scaffold.c */ return fail; }
/* new api */ truf_trod_t truf_trod_rd(const char *str, char **on) { static const char sep[] = " \t\n"; truf_trod_t res; const char *brk; switch (*(brk += strcspn(brk = str, sep))) { case '\0': case '\n': /* no separator, so it's just a symbol * imply exp = 0.df if ~FOO, exp = 1.df otherwise */ if (*str != '~') { res.exp = 1.df; } else { /* could be ~FOO notation */ res.exp = 0.df; str++; } /* also set ON pointer */ if (LIKELY(on != NULL)) { *on = deconst(brk); } break; default: /* get the exposure sorted (hopefully just 1 separator) */ res.exp = strtod32(brk + 1U, on); break; } /* before blindly strdup()ing the symbol check if it's not by * any chance in MMY notation * thankfully the mmy subsystem does the magic for us. */ res.sym = truf_sym_rd(str, NULL); return res; }
static ctl_fld_val_t snarf_fv(ctl_fld_key_t fc, const char *s) { ctl_fld_val_t res = {}; switch (ctl_fld_type(fc)) { case CTL_FLD_TYPE_ADMIN: ; break; case CTL_FLD_TYPE_DATE: ; break; case CTL_FLD_TYPE_RATIO: { char *pp; signed int p; unsigned int q; p = strtol(s, &pp, 10); if (*pp != ':' && *pp != '/') { break; } else if (!(q = strtoul(pp + 1U, &pp, 10))) { break; } /* otherwise ass */ res.ratio = (ctl_ratio_t){p, q}; break; } case CTL_FLD_TYPE_PRICE: { char *pp; _Decimal32 p; p = strtod32(s, &pp); res.price = (ctl_price_t)p; break; } case CTL_FLD_TYPE_PERIO: ; break; case CTL_FLD_TYPE_CUSTM: { char *pp; _Decimal32 v; signed int p; unsigned int q; v = strtod32(s, &pp); if (*pp != '+' && *pp != '-') { break; } p = strtol(pp, &pp, 10); if (pp[0] != '<' || pp[1] != '-') { break; } q = strtoul(pp + 2U, &pp, 10), /* otherwise ass */ res.custm = (ctl_custm_t){.r = (ctl_ratio_t){p, q}, .a = v}; break; } default: return res; }