JE::Number(3pm)

πŸ“¦
version 0.066 Β· 3 versions
, in debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NAME πŸ’–

JE::Number β€” it's giving JavaScript number value, bestie ✨


🌸 SYNOPSIS 🌸

use JE;
use JE::Number;

$j = JE->new;

$js_num = new JE::Number $j, 17;

$perl_num = $js_num->value;

$js_num->to_object; # returns a new JE::Object::Number

πŸŽ€ DESCRIPTION πŸŽ€

Okay so this class is literally the one that implements JavaScript number values for JE. And no, bestie, do not get it twisted with JE::Object::Number β€” that module is out here implementing number objects, while this one handles the primitive values. Two different vibes, iykyk πŸ’…

Right now, this module is just using Perl numbers underneath to store the JavaScript numbers. Lowkey though, whether Perl numbers actually align with the IEEE 754 standard that ECMAScript uses is system-dependent πŸ™ˆ. So if anybody out there needs IEEE 754 compliancy, a patch would be welcome. :-) 🫢

The new method takes a global (JE) object and a number as its two arguments. If that second one is an object with a to_number method whose return value isa JE::Number, then that object's internal value gets used. Otherwise the arg itself is used. (And heads up β€” the precise details of how new behaves when the second arg is an object are subject to change πŸ‘€.) It gets numified Perl-style, so 'nancy' becomes NaN and 'information' becomes Infinity πŸ’€ iconic tbh.

The value method produces a Perl scalar. And the 0+ numeric operator is overloaded and produces the same thing ✨

Stringification and boolification are also overloaded, and they produce the same results as in JavaScript πŸ”₯

The typeof and class methods produce the strings 'number' and 'Number', respectively. Periodt πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹

  • JE
  • JE::Types
  • JE::Object::Number

perl v5.36.0 Β· 2023-08-25 β€” mwah, that's the whole page bestie, go read the other ones too πŸ’œπŸ§šβ­

πŸ“¦ where this page comes from