Mojoler.Dsl.Arith (mojoler v0.1.0)

Copy Markdown View Source

Checked addition generated from tools/dsl/decls.json.

The native wrapper decodes the terms and calls checked_add in native/examples/arith_user.mojo. This module does not declare the NIF entry.

Summary

Functions

Adds a and b as signed 64-bit integers.

Loads priv/native/libdsl_arith.so.

Functions

add(a, b)

@spec add(integer(), integer()) :: {:ok, integer()} | {:error, :overflow}

Adds a and b as signed 64-bit integers.

Both arguments are required integers. There is no optional argument.

Returns

  • {:ok, sum} when the sum fits
  • {:error, :overflow} when it does not

Raises

Examples

iex> Mojoler.Dsl.Arith.add(20, 22)
{:ok, 42}

iex> Mojoler.Dsl.Arith.add(9_223_372_036_854_775_807, 1)
{:error, :overflow}

iex> Mojoler.Dsl.Arith.add(1, :nope)
** (ArgumentError) argument error

load_nif()

@spec load_nif() :: :ok | {:error, term()}

Loads priv/native/libdsl_arith.so.

A second call returns {:error, {:reload, charlist}}.

Examples

iex> Mojoler.Dsl.Arith.load_nif()
{:error, {:reload, ~c"NIF library already loaded (reload disallowed since OTP 20)."}}