PMNUMBERSTR(3)

πŸ“¦
version 7.2.2 Β· 4 versions
, in arch rolling, centos-stream 10, fedora 43, fedora 44, ubuntu resolute, ubuntu stonking

✨ 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.ddT
  • 999995000000 – 999995000 β€” ddd.ddG
  • 999995000 – 999995 β€” ddd.ddM
  • 999995 – 999.995 β€” ddd.ddK
  • 999.995 – 0.005 β€” ddd.dd
  • 0.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