nxt.bound

Bounded arithmetic wrapper type, similar to Ada's range/interval types.

Members

Classes

BoundOverflowException
class BoundOverflowException

Exception thrown when Bound values overflows or underflows.

Enums

Policy
enum Policy

TODO: Use boundness policy.

areCTBoundable
eponymoustemplate areCTBoundable(alias low, alias high)

TODO: use this.

isBoundable
eponymoustemplate isBoundable(T)

Check if type T can wrapped in a Bounded.

isCTBound
eponymoustemplate isCTBound(alias expr)

Check if expression expr is a compile-time-expression that can be used as a Bound.

isCTEable
eponymoustemplate isCTEable(alias expr)

Check if the value of expr is known at compile-time.

Functions

abs
auto abs(Bound!(V, low, high, optional, useExceptions, packed, signed) a)

Calculate absolute value of a.

doIt
auto doIt(ubyte x)

TODO: Can D do better than C++ here? Does this automatically deduce to CommonType and if so do we need to declare it? Or does it suffice to constructors?

max
auto max(Bound!(V1, low1, high1, optional, useExceptions, packed, signed) a1, Bound!(V2, low2, high2, optional, useExceptions, packed, signed) a2)

Calculate Maximum. TODO: variadic.

min
auto min(Bound!(V1, low1, high1, optional, useExceptions, packed, signed) a1, Bound!(V2, low2, high2, optional, useExceptions, packed, signed) a2)

Calculate Minimum. TODO: variadic.

optional
auto optional(V x)

Return x with automatic packed saturation. * * If packed optimize storage for compactness otherwise for speed.

saturated
auto saturated(V x)

Return x with automatic packed saturation.

Structs

Bound
struct Bound(V, alias low, alias high, bool optional = false, bool useExceptions = true, bool packed = true, bool signed = false)

Value of type V bound inside inclusive range [low, high].

Templates

BoundsType
template BoundsType(alias low, alias high, bool packed = true, bool signed = false)

Get type that can contain the inclusive bound [low, high]. If packed optimize storage for compactness otherwise for speed. If signed use a signed integer.

PackedNumericType
template PackedNumericType(alias expr)
Undocumented in source.
bound
template bound(alias value)

Instantiate \c Bound from a single expression expr.

bound
template bound(alias low, alias high, bool optional = false, bool useExceptions = true, bool packed = true, bool signed = false)

Instantiator for \c Bound.

See Also

http://en.wikipedia.org/wiki/Interval_arithmetic

https://bitbucket.org/davidstone/bounded_integer

http://stackoverflow.com/questions/18514806/ada-like-types-in-nimrod

http://forum.dlang.org/thread/xogeuqdwdjghkklzkfhl@forum.dlang.org#post-rksboytciisyezkapxkr:40forum.dlang.org http://forum.dlang.org/thread/lxdtukwzlbmzebazusgb@forum.dlang.org#post-ymqdbvrwoupwjycpizdi:40forum.dlang.org http://dlang.org/operatoroverloading.html

TODO: Test with geometry.Vector or geometry.Point

TODO: Make stuff @safe pure @nogc and in some case nothrow

TODO: Implement overload for conditional operator p ? x1 : x2 TODO: Propagate ranges in arithmetic (opUnary, opBinary, opOpAssign): - Integer: +,-,*,^^,/ - FloatingPoint: +,-,*,/,^^,sqrt,

TODO: Should implicit conversions to un-Bounds be allowed? Not in https://bitbucket.org/davidstone/bounded_integer.

TODO: Merge with limited TODO: Is this a good idea to use?: import std.meta; mixin Proxy!_t; // Limited acts as V (almost). invariant() { enforce(_t >= low && _t <= high); wln("fdsf");

TODO: If these things take to long to evaluted at compile-time maybe we need to build it into the language for example using a new syntax either using - integer(range:low..high, step:1) - int(range:low..high, step:1) - num(range:low..high, step:1)

TODO: Use V saveOp(string op, V)(V x, V y) pure @save @nogc if(isIntegral!V && (op=="+" || op=="-" || op=="<<" || op=="*")) { mixin("x "~op~"= y"); static if(isSigned!V) { static if(op == "*") { asm naked { jnc opok; } } else { asm naked { jno opok; } } x = V.min; } else // unsigned { asm naked { jnc opok; } x = V.max; } opok: return x; }

TODO: Reuse core.checkedint

TODO: Move to Phobos std.typecons

Meta