Date: Fri, 25 Mar 2011 14:33:06 -0700 From: Xin LI <delphij@gmail.com> To: Alexander Best <arundel@freebsd.org> Cc: freebsd-hackers@freebsd.org Subject: Re: Switching to [KMGTPE]i prefixes? Message-ID: <AANLkTinEcT__Wtc6LkSyqqMnQwuKVUbZC4dPZvZH_dSX@mail.gmail.com> In-Reply-To: <20110325195325.GA69264@freebsd.org> References: <20110325002115.GA323@freebsd.org> <20110325015508.GA14565@freebsd.org> <20110325024658.GA19544@freebsd.org> <336A9ACD-29BF-41C9-BC25-917CC1E4587D@bsdimp.com> <20110325195325.GA69264@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--00032556582eec92cd049f555622 Content-Type: text/plain; charset=UTF-8 FYI I have a patch and I have incorporated some of Alexander's idea. Difference: - Use of both HN_DIVISOR_1000 and HN_IEC_PREFIXES triggers an assertion. I think it doesn't make sense to return since this is an API violation and we should just tell the caller explicitly; - DIVISOR_1000 and !1000 cases use just same prefixes, so merge them while keeping divisor intact; - Make prefixes table consistently long. I have no strong opinion on this one, though, it's just what my original version used and I can change it to the way Alexander did if there is an advantage of doing that way. (Note, it seems that we use HN_ prefix for both 'scale' and 'flags', I have sorted them by value but HN_IEC_PREFIXES should really belong to the flags group). Cheers, -- Xin LI <delphij@delphij.net> http://www.delphij.net --00032556582eec92cd049f555622 Content-Type: text/x-patch; charset=US-ASCII; name="humanize_number.c.diff" Content-Disposition: attachment; filename="humanize_number.c.diff" Content-Transfer-Encoding: base64 X-Attachment-Id: f_glpmfu710 SW5kZXg6IGh1bWFuaXplX251bWJlci5jCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIGh1bWFuaXplX251bWJlci5j CShyZXZpc2lvbiAyMjAwMDkpCisrKyBodW1hbml6ZV9udW1iZXIuYwkod29ya2luZyBjb3B5KQpA QCAtNTQsMjkgKzU0LDMxIEBACiAJYXNzZXJ0KGJ1ZiAhPSBOVU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B4NDAKIAogLyogaGV4ZHVtcCgzKSAqLwogI2RlZmluZQlIRF9DT0xVTU5fTUFTSwkJMHhmZgo= --00032556582eec92cd049f555622--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTinEcT__Wtc6LkSyqqMnQwuKVUbZC4dPZvZH_dSX>