qprefix/bprefix: use uintmax_t for decimal

This commit is contained in:
nick black 2020-05-17 02:14:27 -04:00
parent 3b9232217e
commit eb72a4612d
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
4 changed files with 8 additions and 7 deletions

View File

@ -21,6 +21,8 @@ rearrangements of Notcurses.
its third argument. This is the absolute time viz `CLOCK_MONOTONIC` through
which the frame ought be displayed. The callback must now effect delay.
* Mouse coordinates are now properly translated for any margins.
* `qprefix()` and `bprefix()` now take a `uintmax_t` in place of an
`unsigned`, to match `ncprefix`.
* 1.4.1 (2020-05-11)
* No user-visible changes (fixed two unit tests).

View File

@ -61,17 +61,17 @@ namespace ncpp
return *_instance == nullptr || _instance->nc == nullptr;
}
static const char* ncmetric (uintmax_t val, unsigned decimal, char *buf, int omitdec, unsigned mult, int uprefix) noexcept
static const char* ncmetric (uintmax_t val, uintmax_t decimal, char *buf, int omitdec, unsigned mult, int uprefix) noexcept
{
return ::ncmetric (val, decimal, buf, omitdec, mult, uprefix);
}
static const char* qprefix (uintmax_t val, unsigned decimal, char *buf, int omitdec) noexcept
static const char* qprefix (uintmax_t val, uintmax_t decimal, char *buf, int omitdec) noexcept
{
return ::qprefix (val, decimal, buf, omitdec);
}
static const char* bprefix (uintmax_t val, unsigned decimal, char *buf, int omitdec) noexcept
static const char* bprefix (uintmax_t val, uintmax_t decimal, char *buf, int omitdec) noexcept
{
return ::bprefix (val, decimal, buf, omitdec);
}

View File

@ -2387,13 +2387,13 @@ API const char* ncmetric(uintmax_t val, uintmax_t decimal, char* buf,
// Mega, kilo, gigafoo. Use PREFIXSTRLEN + 1.
static inline const char*
qprefix(uintmax_t val, unsigned decimal, char* buf, int omitdec){
qprefix(uintmax_t val, uintmax_t decimal, char* buf, int omitdec){
return ncmetric(val, decimal, buf, omitdec, 1000, '\0');
}
// Mibi, kebi, gibibytes. Use BPREFIXSTRLEN + 1.
static inline const char*
bprefix(uintmax_t val, unsigned decimal, char* buf, int omitdec){
bprefix(uintmax_t val, uintmax_t decimal, char* buf, int omitdec){
return ncmetric(val, decimal, buf, omitdec, 1024, 'i');
}

View File

@ -5,8 +5,7 @@
#include "notcurses/notcurses.h"
const char *ncmetric(uintmax_t val, uintmax_t decimal, char *buf, int omitdec,
unsigned mul, int uprefix){
const unsigned mult = mul; // FIXME kill
unsigned mult, int uprefix){
// these two must have the same number of elements
const wchar_t prefixes[] = L"KMGTPEZY"; // 10^21-1 encompasses 2^64-1
const wchar_t subprefixes[] = L"mµnpfazy"; // 10^24-1