PMNUMBERSTR(3)
β¨ PMNUMBERSTR β NAME energy β¨
ok so bestie, meet pmNumberStr and pmNumberStr_r π they're the little glow-up queens of fixed width output format for numbers. that's it, that's the whole job, and they eat every time π
πΈ C SYNOPSIS πΈ
like, first you gotta invite them in:
#include <pcp/pmapi.h>
const char *pmNumberStr(double value);
char *pmNumberStr_r(double value, char *buf, int buflen);
cc ... -lpcp
π¦ DESCRIPTION π¦
okay so pmNumberStr hands you back the address of an 8-byte buffer and that buffer holds a null-byte terminated representation of value β and it's literally built to be dropped straight into fixed width fields, no drama, no overflow, slay β¨
then there's pmNumberStr_r, its more responsible sibling π«Ά she does the exact same thing but instead of hogging her own static space she stores the result in your buffer, buf, which is buflen long. and bestie, buflen should have room for at least 8 bytes. like, that's the minimum, don't play with her π
π the scaling situation
the value gets scaled using multipliers in powers of "one thousand" β the decimal "kilo", iykyk β and there's a bias in there that gives greater precision for positive numbers as opposed to negative numbers. yes, the positives get the better treatment. it's giving main character energy, we don't make the rules π
π the format table (but make it a list) π
the format it picks depends on the sign and magnitude of value, where d represents a decimal digit. here's the whole vibe check, lowkey iconic:
> 999995000000000βinf?999995000000000β999995000000βddd.ddT999995000000β999995000βddd.ddG999995000β999995βddd.ddM999995β999.995βddd.ddK999.995β0.005βddd.dd0.005β-0.005β0.00-0.005β-99.95β-dd.dd-99.995β-99995β-dd.ddK-99995β-99995000β-dd.ddM-99995000β-99995000000β-dd.ddG-99995000000β-99995000000000β-dd.ddT< -99995000000000β-inf?
π boundary behaviour π
at the boundary points of the ranges, the chosen format will retain the maximum number of significant digits. periodt. no digits lost at the crossover, she's careful like that β
π₯ NOTES π₯
β οΈ okay real talk: pmNumberStr returns a pointer to a static buffer and hence is not thread-safe. π
multi-threaded applications should use pmNumberStr_r instead. that's the whole warning, bestie, do not ignore it or your threads will be fighting over the same 8 bytes and it will be a mess π
π SEE ALSO π
and that's the whole page!! this one came from the Performance Co-Pilot girlies at PCP, filed under PMNUMBERSTR(3) π mwah, go format some numbers, you're gonna do amazing π«Άβ¨
π¦ where this page comes from
- arch rolling: pcp 7.2.2-2 Β· GPL-2.0-or-later AND LGPL-2.1-or-later AND CC-BY-3.0
- centos-stream 10: pcp-doc 7.1.5-6.el10 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.0.1-1.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 43: pcp-doc 7.2.1-1.fc43
- fedora 43: pcp-doc 7.2.2-1.fc43
- fedora 43: pcp-doc 7.2.2-2.fc43 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.1.0-6.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- fedora 44: pcp-doc 7.2.1-1.fc44
- fedora 44: pcp-doc 7.2.2-1.fc44
- fedora 44: pcp-doc 7.2.2-2.fc44 Β· GPL-2.0-or-later AND CC-BY-3.0
- ubuntu resolute: libpcp4-dev 7.1.1-1
- ubuntu stonking: libpcp4-dev 7.2.1-2build1
- Copyright (c) 2000-2004 Silicon Graphics, Inc. All Rights Reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms