luna-complex
This manual documents the code of Luna-Flow/luna-complex at version 0.2.0
(the version in moon.mod) on MoonBit 0.10, including the unreleased changes
listed in CHANGELOG.md.
Overview
Luna-Flow/luna-complex provides complex numbers for Luna Flow. The root
package defines the generic type Complex[T], the ring
over any scalar T, with its arithmetic and luna-generic structure
instances. The float_backend package adds the analytic functions of
Complex[Double] (roots, logarithms, powers, trigonometric and hyperbolic
functions and their inverses) with numerically stable formulas, and the
capability traits for floating-point scalars.
Install
moon add Luna-Flow/luna-complex@0.3.2
Then import the packages you need in your moon.pkg. The examples in this
manual use these aliases:
import {
"Luna-Flow/luna-complex" @complex,
"Luna-Flow/luna-complex/float_backend" @fb,
}
The packages need the MoonBit toolchain 0.10.20 or later (moonc ≥ 0.10.20) with
moon.mod / moon.pkg manifests; the tests run on wasm-gc, wasm, js
and native. They depend on Luna-Flow/luna-generic 0.4.0,
Luna-Flow/arithmetic 0.5.0 and Kaida-Amethyst/math.
Pages
The root package is documented under the name core. float_backend
replaces the former double_ext package.
| Part | Tutorial | API | Design |
|---|---|---|---|
core (Luna-Flow/luna-complex): generic Complex[T], arithmetic, structure instances | tutorial | API | design |
float_backend (Luna-Flow/luna-complex/float_backend): analytic functions of Complex[Double], floating-point capability traits | tutorial | API | design |
The contribution guide collects the rules for changing the code and the manual.
Exported items
core: the typeComplex[T]withnew,set,set_re,set_im,zero,one,add,sub,neg,mul,div,conjugate,inv,equalandto_stringcoreinstances:Add,Sub,Neg,Mul,Div,Show, and theluna-generictraitsZero,One,AddMonoid,AddGroup,MulMonoid,Semiring,Ring,Inverse,MulGroup,FieldandConjugatefloat_backendmodulus and argument:abs,abs_sqr,abs_log,arg,polarfloat_backendarithmetic:div,sqrt,sqrt_real,exp,log,log_10,log_b,pow,pow_real,op_bin_re,op_bin_imfloat_backendtrigonometric and hyperbolic functions:sin,cos,tan,sec,csc,cot,sinh,cosh,tanh,sech,csch,cothfloat_backendinverse functions:asin,acos,atan,asec,acsc,acot,asinh,acosh,atanh,asech,acsch,acoth, and the real-argument formsasin_real,acos_real,asec_real,acsc_real,acosh_real,atanh_realfloat_backendstorage:pack,native_packfloat_backendtraits:FloatingAnalyticScalar,FloatingSpecialValues,FloatingBackendScalar, and the re-exported typeComplex
Where to read next
The core tutorial computes with Complex[T], and the
float_backend tutorial adds roots, logarithms
and trigonometry. The API pages state the branch, special-value and abort
behaviour of every item, and the design pages derive the algebra and the
stable formulas.
- New to the package: read the core tutorial, then the float_backend tutorial.
- Using it in a library: keep the core API and the float_backend API at hand; the latter states the branch, special-value and abort behaviour of every function, including the known deviations on the negative real axis.
- Contributing: read the core design for the algebra and the lawfulness of the instances, the float_backend design for the derivations of the stable formulas and the branch cuts, and the contribution guide.
Validation
Recommended release checks:
moon check --target all
moon test
moon info