fixed(3)

πŸ“¦
version 5.2.2 Β· 2 versions
, in fedora 43, fedora 44

🌸 fixed(3) 🌸

Erlang Module Definition β€” yes bestie, it's the fixed module, and we're about to make CORBA's most extra number type make sense. πŸŽ€


✨ NAME ✨

fixed β€” it's giving "the corba fixed type". πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so. This module is literally just a bunch of functions that hand you an interface to the CORBA fixed type. That's the whole vibe. 🌈

The type Fixed that we keep talking about down below is defined like this:

-record(fixed, {digits, scale, value}).

So <green>digits</green> is the total amount of digits it consists of, and <green>scale</green> is the number of fractional digits. The <green>value</green> field holds the actual Fixed value, and it's represented as an integer. The limitations of each field are, no cap:

  • Digits β€” integer(), -1 > Digits < 32
  • Scale β€” integer(), -1 > Scale =< Digits
  • Value β€” integer(), range (31 digits): +/-9999999999999999999999999999999

Since the Value part is represented by an integer, it is vital that the Digits and Scale values are correct. And this also means that trailing zeros cannot be left out in some cases, bestie, I'm so serious:

  • fixed<5,3> eq. 03.140d eq. 3140
  • fixed<3,2> eq. 3.14d eq. 314

Leading zeros, though? Those can be left out. Slay. ✨

For your convenience, this module exports functions which handle unary (-) and binary (+-*/) operations legal for the Fixed type. Since a unary + have no effect, this module do not export such a function β€” correct, bestie, it simply doesn't exist, don't look for it. πŸ™ˆ

Any of the binary operations may cause an overflow (i.e. more than 31 significant digits; leading and trailing zeros are not considered significant). If this is the case, the Digit and Scale values are adjusted and the Value truncated (no rounding performed β€” nope, we do not round in this house). This behavior is compliant with the OMG CORBA specification. Each binary operation have the following upper bounds:

  • Fixed1 + Fixed2 β€” fixed<max(d1-s1,d2-s2) + max(s1,s2) + 1, max(s1,s2)>
  • Fixed1 - Fixed2 β€” fixed<max(d1-s1,d2-s2) + max(s1,s2) + 1, max(s1,s2)>
  • Fixed1 * Fixed2 β€” fixed<d1+d2, s1+s2>
  • Fixed1 / Fixed2 β€” fixed<(d1-s1+s2) + Sinf ,Sinf >

A quotient may have an arbitrary number of decimal places, which is denoted by a scale of Sinf. Main character behavior tbh. πŸ‘‘


πŸ’– EXPORTS πŸ’–

🌟 create(Digits, Scale, Value) -> Result

Types:

Result = Fixed Type | {'EXCEPTION', #'BAD_PARAM'{}}

This function creates a new instance of a Fixed Type. If the limitations is not fulfilled (e.g. overflow) an exception is raised. πŸ’€

🌟 get_typecode(Fixed) -> Result

Types:

Result = TypeCode | {'EXCEPTION', #'BAD_PARAM'{}}

Returns the TypeCode which represents the supplied Fixed type. If the parameter is not of the correct type, an exception is raised.

🌟 add(Fixed1, Fixed2) -> Result

Types:

Result = Fixed1 + Fixed2 | {'EXCEPTION', #'BAD_PARAM'{}}

Performs a Fixed type addition. If the parameters are not of the correct type, an exception is raised. πŸ“

🌟 subtract(Fixed1, Fixed2) -> Result

Types:

Result = Fixed1 - Fixed2 | {'EXCEPTION', #'BAD_PARAM'{}}

Performs a Fixed type subtraction. If the parameters are not of the correct type, an exception is raised.

🌟 multiply(Fixed1, Fixed2) -> Result

Types:

Result = Fixed1 * Fixed2 | {'EXCEPTION', #'BAD_PARAM'{}}

Performs a Fixed type multiplication. If the parameters are not of the correct type, an exception is raised. πŸ”₯

🌟 divide(Fixed1, Fixed2) -> Result

Types:

Result = Fixed1 / Fixed2 | {'EXCEPTION', #'BAD_PARAM'{}}

Performs a Fixed type division. If the parameters are not of the correct type, an exception is raised.

🌟 unary_minus(Fixed) -> Result

Types:

Result = -Fixed | {'EXCEPTION', #'BAD_PARAM'{}}

Negates the supplied Fixed type. If the parameter is not of the correct type, an exception is raised. πŸ¦‹


And that's the whole page, bestie. Every flag, every bound, every exception β€” we kept it all, we just made it cute. πŸ’œ

Brought to you by Ericsson AB 🫢, shipping with orber 5.2.2, and this lil masterpiece is dated fixed(3). Go forth and don't overflow. Periodt. πŸ‘‘βœ¨

πŸ“¦ where this page comes from