GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

πŸ’– GOLF(2gg) πŸ’–

okay bestie, welcome to the GOLF(2gg) manual page, and today's main character is a little function called string-number πŸŽ€ she's in the Development chapter and she's here to do exactly one (1) thing and do it slayfully.


✨ NAME ✨

string-number β€” (numbers) πŸ¦‹


🎯 PURPOSE 🎯

Convert string to number. that's it. that's the whole vibe. πŸ’…


πŸ“œ SYNTAX πŸ“œ

string-number <string> [ to <number> ] \
    [ base <base> ] \
    [ status <status> ]

look at her. three optional clauses. she's flexible, she's lowkey iconic. 🫢


🌸 DESCRIPTION 🌸

so here's the tea, fr fr: <string> gets converted into <number> in the to clause, and it does that using <base> from the base clause. and what's the default base, you ask? it depends, bestie, it literally depends:

  • 10 β€” the normie default
  • 16 β€” if the number is prefixed with "0x" or "0X", and no, a leading minus or plus sign doesn't count, so don't try it πŸ™ˆ
  • 8 β€” if the number is prefixed with "0", and again, excluding any leading minus or plus sign

<base> can be anywhere from 2 to 36, inclusive β€” she contains multitudes ✨. <number> can be positive or negative (i.e. signed, she's got range) and can be up to 64-bit in length. and if <base> is 0, that's the same as not specifying it at all β€” default behavior applies, no notes. πŸ’…

now for the status tea, because this is where it gets real. the <status> number in the status clause is GG_OKAY if the conversion was successful πŸŽ‰. but if it was NOT successful, then <number> is 0 and <status> tells you why:

  • GG_ERR_OVERFLOW β€” if <string> represents a number that needs over 64 bits of storage. she's too much, she's overflowing, she cannot be contained 😭
  • GG_ERR_INVALID β€” if <base> is incorrect
  • GG_ERR_EXIST β€” if <string> is empty or no digits were specified
⚠️ and here's the one you gotta remember: if there are trailing invalid characters (think "182xy" in base 10), then <number> becomes the result of the conversion up to the first invalid character, and <status> is GG_ERR_TOO_MANY. in that exact example, <number> would be 182. she takes what she can get and leaves the rest behind πŸ’€

🌈 EXAMPLES 🌈

in this example, number "n" would be 49 and status "st" would be GG_OKAY β€” we love a clean success story πŸ‘‘

string-number "49" to n base 10 status st

πŸ‘€ SEE ALSO πŸ‘€

  • Numbers

abs-number number-expressions number-string set-number string-number See all documentation


and that's the whole page, bestie!! no cap, you're now certified in string-number πŸ§šπŸ’œ

$VERSION Β· $DATE Β· GOLF(2gg) β€” mwah, go forth and convert ✨🌸

πŸ“¦ where this page comes from