BSON::Double(3pm)
π BSON::Double π
okay bestie, so this is BSON::Double β it's a BSON type wrapper for a Double. that's it, that's the vibe. it's the lil' Perl module that holds a number so BSON knows to treat it like a double. π«Ά
it's part of the User Contributed Perl Documentation crowd, and this particular version is version v1.12.2. β¨
πΈ SYNOPSIS πΈ
like, here's how you'd actually use it:
use BSON::Types ':all';
my $bytes = bson_double( $number );
you pull in BSON::Types with :all (yes, all of them, we're greedy π
) and then bson_double( $number ) gives you back the wrapper. periodt.
π¦ DESCRIPTION π¦
so basically: this module provides a BSON type wrapper for a numeric value that would be represented in BSON as a double. if you've got a number and you need BSON to see it as a double specifically, this is your girl. no cap. π
β¨ ATTRIBUTES β¨
π value
a numeric scalar β OR, plot twist, one of the special strings "Inf", "-Inf" or "NaN". π
this gets coerced to Perl's numeric type, so don't stress too hard about what you hand it.
the default is 0.0. cute, lowkey, iconic. β
π METHODS π
π TO_JSON
returns a double. simple as.
BUT here's the lore, bestie:
- if the
BSON_EXTJSONenvironment variable is true and theBSON_EXTJSON_RELAXEDenvironment variable is false, it returns a hashref compatible with MongoDB's extended JSON format, which represents it as a document like this:
{"$numberDouble" : "42.0"}
- if
BSON_EXTJSONis false and the value is'Inf','-Inf'or'NaN'β which are, and I cannot stress this enough, illegal in regular JSON β then an exception gets thrown. π
so yeah, watch out for that. if you're not in extJSON mode and you try to serialize infinity or NaN into plain JSON, it's gonna blow up in your face. that's not a vibe, that's an exception.
π§ INFINITY AND NAN π§
some Perls may not support converting "Inf" or "NaN" strings to their double equivalent. rude, honestly. π
they are available as functions from the POSIX module β but as a lighter alternative to POSIX, these lil' helpers are available:
BSON::Double::pInf()β positive infinity πBSON::Double::nInf()β negative infinity π€BSON::Double::NaN()β not-a-number π«
use these instead if you don't wanna drag all of POSIX in. slay. π
π OVERLOADING π
the numification operator, 0+, is overloaded to return the value. so if you treat the object like a number, it just is the number. main character energy fr fr.
the full "minimal set" of overloaded operations is provided (per the overload documentation, iykyk), and fallback overloading is enabled. β¨
πΈ AUTHORS πΈ
the legends who made this happen:
- David Golden <david@mongodb.com>
- Stefan G. <minimalist@lavabit.com>
π COPYRIGHT AND LICENSE π
this software is Copyright (c) 2020 by Stefan G. and MongoDB, Inc.
it's free software, licensed under:
The Apache License, Version 2.0, January 2004
okay that's the whole page bestie!! π this was generated as part of perl v5.30.3, dated 2020-08-14, for the one and only BSON::Double(3pm). go forth and wrap those doubles. π¦β¨ no cap, you got this. π«Ά
π¦ where this page comes from
- debian bookworm: libbson-perl 1.12.2-1 Β· Apache-2.0
- ubuntu jammy: libbson-perl 1.12.2-1 Β· Apache-2.0
- ubuntu noble: libbson-perl 1.12.2-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms