MTL5 -- Matrix Template Library C++ API
mtl:: -- C++20 header-only linear algebra for mixed-precision algorithm design
Loading...
Searching...
No Matches
mtl::Field Concept Reference

A type that forms a mathematical field: division is defined AND invertible. More...

#include <scalar.hpp>

Concept definition

template<typename T>
concept mtl::Field = Scalar<T> && !std::is_integral_v<T> && requires(T a, T b) {
{ a / b } -> std::convertible_to<T>;
}
A type that forms a mathematical field: division is defined AND invertible.
Definition scalar.hpp:48
A type that behaves like a scalar value (arithmetic or custom number type), and describes itself thro...
Definition scalar.hpp:27

Detailed Description

A type that forms a mathematical field: division is defined AND invertible.

Integral types are excluded, and that exclusion is the point. int satisfies the syntax – a / b compiles and yields an int – so a purely syntactic Field admitted the integers, which are a RING, not a field: 3/2*2 == 2, and only 1 and -1 have inverses. Every algorithm that says requires Field means "I will divide and expect the quotient back", and on integers it silently gets a truncated one. That is how lu_factor(dense2D<int>) used to compile and return confident nonsense.

Custom number types (posit, LNS, fixpnt, rationals) are unaffected: they are not std::is_integral and their division is the operation they advertise.