BSON::Double(3pm)

πŸ“¦
version 1.12.2 Β· 5 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

πŸ’– 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_EXTJSON environment variable is true and the BSON_EXTJSON_RELAXED environment 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_EXTJSON is 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>

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