Guidance for AI agents working on the DecimalEnv library.
DecimalEnv is a small Elixir library (~2 modules, ~830 LOC) that provides a
decimal macro for running a block of code with Decimal arithmetic under
regular Elixir operators. It depends on Decimal ~> 3.0.
lib/decimal_env.ex— publicdecimal/1anddecimal/2macros plus theget_context/1andconvert_type/2helpers.lib/decimal_env/operators.ex— operator overloads (arithmetic, comparison,abs,min,max,div,rem,round,ceil,floor,sqrt,inf,inf?,number?,integer?) imported viause DecimalEnv.Operators.
- Erlang/OTP 29, Elixir 1.20 (see
.tool-versions). - Minimum supported: Elixir 1.15 / OTP 26 (see
mix.exsand CI matrix). - Use
mixfor all tasks.
Run all of these before considering work complete. CI runs the same set
(.github/workflows/checks.yml) and any one of them can fail independently.
mix format --dry-run --check-formatted # formatting
mix credo --strict # lint
mix test # doctests + unit tests
mix dialyzer # type checks
mix compile --warnings-as-errors is also enforced in CI; run it if you
change lib/.
The library has very few traditional unit tests; doctests are the primary
test mechanism. Most functions in DecimalEnv.Operators carry iex> blocks
that double as both documentation and tests.
test/decimal_env_test.exs— unit tests for thedecimalmacros and theget_context/1/convert_type/2helpers.test/decimal_env/operators_test.exs— additional unit tests for cases the doctests don't cover (e.g. allround/3strategies,+Inf/-Inf/NaNedge cases). It begins withdoctest DecimalEnv.Operators.
When adding a new operator or function, prefer extending its @doc with
iex> examples over writing a separate unit test — doctest DecimalEnv.Operators will pick them up automatically.
- Operators cannot be invoked remotely.
DecimalEnv.Operators.+(a, b)is a syntax error. Inside thedecimalblock the operators are imported; in tests outside the block, call the underlying named function (DecimalEnv.Operators.round/3,.div/2,.inf?/1,.>(a, b), etc.) instead. The comparison operators>,<,>=,<=,==,!=can be called remotely because they parse as atoms, but the arithmetic operators (+,-,*,/, unary+, unary-) cannot. use DecimalEnv.Operatorsis a compile-time macro and cannot be invoked inside a test body. If a test genuinely needs the import (e.g. to exercise the unary+operator), define a smalldefmoduleinside the test module that doesuse DecimalEnv.Operatorsand expose a wrapper. Avoid this unless strictly necessary — prefer calling the named function directly.__using__/1is implicitly covered by everyiex>block inDecimalEnv.Operators(each one starts withuse DecimalEnv.Operators).
mix formatis the source of truth. Line length is 80 (see.formatter.exs).decimal/1anddecimal/2are listed underlocals_without_parens, so writedecimal do: .../decimal as: :integer do: ...without parens.- Never hand-align code to satisfy the formatter; run
mix formatand commit its output.
- No comments unless explicitly requested (matches the rest of the codebase).
- Keep
@specannotations on every public and private function — they are load-bearing formix dialyzer. - Public API changes deserve a
CHANGELOG.mdentry under the current@versioninmix.exs.