Scalar...Numeric(3pm)

πŸ’– Scalar...Numeric πŸ’–

okay bestie, welcome to Scalar::Util::Numeric(3pm) ✨ β€” it's a User Contributed Perl Documentation page and it is, no cap, the vibe check your scalars have been begging for 🫢


🌸 NAME 🌸

Scalar::Util::Numeric β€” numeric tests for perl scalars πŸ”’πŸ’…


✨ SYNOPSIS ✨

use Scalar::Util::Numeric qw(isnum isint isfloat);

foo($bar / 2) if (isnum $bar);

if (isint $baz) {
    # ...
} elsif (isfloat $baz) {
    # ...
}

like... four lines and you're already the main character πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

So here's the tea β˜•: this module exports a bunch of lil wrappers around perl's builtin grok_number function. And what does grok_number do? It returns the numeric type of whatever you throw at it β€” or 0 if your argument isn't numeric at all 😭. Not numeric = zero, periodt.


πŸŽ€ TAGS πŸŽ€

Every single function in Scalar::Util::Numeric can be pulled in at once with the :all tag, iconic behaviour honestly πŸ‘‘

use Scalar::Util::Numeric qw(:all);

πŸ’œ EXPORTS πŸ’œ

⭐ isnum ⭐

isnum ($val)

Returns a nonzero value (which is your hint at the numeric type) if $val is a number. Not a bool, not a vibe β€” it's the type, encoded πŸ”₯

And that numeric type? It's a conjunction of these flags right here:

0x01  IS_NUMBER_IN_UV               (number within UV range - not necessarily an integer)
0x02  IS_NUMBER_GREATER_THAN_UV_MAX (number is greater than UV_MAX)
0x04  IS_NUMBER_NOT_INT             (saw . or E notation)
0x08  IS_NUMBER_NEG                 (leading minus sign)
0x10  IS_NUMBER_INFINITY            (Infinity)
0x20  IS_NUMBER_NAN                 (NaN - not a number)

🌈 isint / isuv / isbig / isfloat / isneg / isinf / isnan 🌈

These are the lil flavours of isnum (each one matching a flag up there πŸ‘†) and they're all available too:

isint
isuv
isbig
isfloat
isneg
isinf
isnan

isint is the dramatic one: it returns -1 if its operand is a negative integer, 1 if it's 0 or a positive integer, and 0 otherwise. Three moods, one function πŸ’€

The others? They're chill. They always return 1 or 0. no in-between, no chaos 🧚


πŸ‘‘ SEE ALSO πŸ‘‘

Go read these too, bestie, they're all part of the extended universe 🫢

  • "type" in autobox
  • Data::Types
  • Params::Classify
  • Params::Util
  • Scalar::Util
  • String::Numeric

πŸ“ VERSION πŸ“

0.40 β€” yes, that's the one you want ✨


πŸ’– AUTHORS πŸ’–

  • chocolateboy <chocolate@cpan.org>
  • Michael G. Schwern <schwern@pobox.com>

Copyright (c) 2005-2014, chocolateboy.

This module is free software. It may be used, redistributed and/or modified under the same terms as Perl itself. 🫢


and that's the whole page, bestie πŸ’… go forth and grok those numbers. iykyk.

okay love u bye β€” this was perl v5.42.3, dated 2026-08-19, and the page you just read was Scalar...Numeric(3pm) πŸŽ€πŸ’–βœ¨

πŸ“¦ where this page comes from