expand_number(3)

Phil Shafer phil at juniper.net
Wed Jul 10 21:29:31 UTC 2019


Would a reasonable goal be to make expand_number and humanize_number 
(with HN_IEC_PREFIXES) should be as compatible as possible?

The API doesn't allow many humanize-style features, but having the 
number->string->number work would be ideal so support for 
HN_DECIMAL-style input should be added, so "1.1K" does the right thing 
(thought it rounds to 1126).

Lacking support for "suffix", trailing garbage should not be an error 
(ala atoi), though I wish there was a parameter like strtol()'s endptr 
to pass the next point to the character back in.  If there was a suffix 
parameter, the endptr would be skipped over it, if present.

The expand_number API uses uint64_t where humanize_number uses signed 
int64_t so the answer for negative numbers is DOA.

Is it worth making a new expandize_number() function 
(dehumanize_number?) that brings the API more into sync with 
humanize_number?

Thanks,
  Phil



On 10 Jul 2019, at 14:14, John Baldwin wrote:

> While working on some bhyve changes I happened to look at the source
> to expand_number(3) and noticed what I think are several bugs.  I
> wrote some tests to validate that these bugs are present, but in some
> cases I'm not sure what the correct / desired behavior is?  I posted
> a review with the tests and questions about what some of the behavior
> should be with folks who have worked on expand_number(3) previously,
> but haven't gotten any feedback.  The URL to the review is below if
> other folks would like to offer feedback on some of my open questions
> such as should we support negative numbers, hex and octal bases,
> trailing garbage, etc.?
>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.freebsd.org_D20796&d=DwICAg&c=HAkYuh63rsuhr6Scbfh0UjBXeMK-ndb3voDTXcWzoCI&r=And7spKEXmRNIrq8pYCiSg&m=EHG6EmocNCDS6VoOZVxzZoCq-BqbJjBpsC9kXhGFTd0&s=bUQ8xvhg6vv95W5fHxswOrzDIeVxFsFJIa2582tjHgA&e=
>
> -- 
> John Baldwin
> _______________________________________________
> freebsd-arch at freebsd.org mailing list
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.freebsd.org_mailman_listinfo_freebsd-2Darch&d=DwICAg&c=HAkYuh63rsuhr6Scbfh0UjBXeMK-ndb3voDTXcWzoCI&r=And7spKEXmRNIrq8pYCiSg&m=EHG6EmocNCDS6VoOZVxzZoCq-BqbJjBpsC9kXhGFTd0&s=_ChOm4nn2d9pTlDuA6I2EdYXc73LOiS_N4c0k0DOWPo&e=
> To unsubscribe, send any mail to 
> "freebsd-arch-unsubscribe at freebsd.org"


More information about the freebsd-arch mailing list