mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 13:40:20 +03:00
Merge pull request #9083 from tim-dlang/issue24851
Fix bugzilla 24851 - Some members of CustomFloat can have const this
This commit is contained in:
commit
db798688e4
1 changed files with 18 additions and 7 deletions
|
@ -223,7 +223,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert the current value to signed exponent, normalized form
|
// Convert the current value to signed exponent, normalized form
|
||||||
void toNormalized(T,U)(ref T sig, ref U exp)
|
void toNormalized(T,U)(ref T sig, ref U exp) const
|
||||||
{
|
{
|
||||||
sig = significand;
|
sig = significand;
|
||||||
auto shift = (T.sizeof*8) - precision;
|
auto shift = (T.sizeof*8) - precision;
|
||||||
|
@ -490,7 +490,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns: real part
|
/// Returns: real part
|
||||||
@property CustomFloat re() { return this; }
|
@property CustomFloat re() const { return this; }
|
||||||
|
|
||||||
/// Returns: imaginary part
|
/// Returns: imaginary part
|
||||||
static @property CustomFloat im() { return CustomFloat(0.0f); }
|
static @property CustomFloat im() { return CustomFloat(0.0f); }
|
||||||
|
@ -546,7 +546,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetches the stored value either as a `float`, `double` or `real`.
|
/// Fetches the stored value either as a `float`, `double` or `real`.
|
||||||
@property F get(F)()
|
@property F get(F)() const
|
||||||
if (staticIndexOf!(immutable F, immutable float, immutable double, immutable real) >= 0)
|
if (staticIndexOf!(immutable F, immutable float, immutable double, immutable real) >= 0)
|
||||||
{
|
{
|
||||||
import std.conv : text;
|
import std.conv : text;
|
||||||
|
@ -591,14 +591,14 @@ public:
|
||||||
// Define an opBinary `CustomFloat op CustomFloat` so that those below
|
// Define an opBinary `CustomFloat op CustomFloat` so that those below
|
||||||
// do not match equally, which is disallowed by the spec:
|
// do not match equally, which is disallowed by the spec:
|
||||||
// https://dlang.org/spec/operatoroverloading.html#binary
|
// https://dlang.org/spec/operatoroverloading.html#binary
|
||||||
real opBinary(string op,T)(T b)
|
real opBinary(string op,T)(T b) const
|
||||||
if (__traits(compiles, mixin(`get!real`~op~`b.get!real`)))
|
if (__traits(compiles, mixin(`get!real`~op~`b.get!real`)))
|
||||||
{
|
{
|
||||||
return mixin(`get!real`~op~`b.get!real`);
|
return mixin(`get!real`~op~`b.get!real`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ditto
|
/// ditto
|
||||||
real opBinary(string op,T)(T b)
|
real opBinary(string op,T)(T b) const
|
||||||
if ( __traits(compiles, mixin(`get!real`~op~`b`)) &&
|
if ( __traits(compiles, mixin(`get!real`~op~`b`)) &&
|
||||||
!__traits(compiles, mixin(`get!real`~op~`b.get!real`)))
|
!__traits(compiles, mixin(`get!real`~op~`b.get!real`)))
|
||||||
{
|
{
|
||||||
|
@ -606,7 +606,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ditto
|
/// ditto
|
||||||
real opBinaryRight(string op,T)(T a)
|
real opBinaryRight(string op,T)(T a) const
|
||||||
if ( __traits(compiles, mixin(`a`~op~`get!real`)) &&
|
if ( __traits(compiles, mixin(`a`~op~`get!real`)) &&
|
||||||
!__traits(compiles, mixin(`get!real`~op~`b`)) &&
|
!__traits(compiles, mixin(`get!real`~op~`b`)) &&
|
||||||
!__traits(compiles, mixin(`get!real`~op~`b.get!real`)))
|
!__traits(compiles, mixin(`get!real`~op~`b.get!real`)))
|
||||||
|
@ -615,7 +615,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ditto
|
/// ditto
|
||||||
int opCmp(T)(auto ref T b)
|
int opCmp(T)(auto ref T b) const
|
||||||
if (__traits(compiles, cast(real) b))
|
if (__traits(compiles, cast(real) b))
|
||||||
{
|
{
|
||||||
auto x = get!real;
|
auto x = get!real;
|
||||||
|
@ -949,6 +949,17 @@ public:
|
||||||
assertThrown!AssertError(a = float.infinity);
|
assertThrown!AssertError(a = float.infinity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@safe unittest
|
||||||
|
{
|
||||||
|
const CustomFloat!16 x = CustomFloat!16(3);
|
||||||
|
assert(x.get!float == 3);
|
||||||
|
assert(x.re.get!float == 3);
|
||||||
|
assert(x + x == 6);
|
||||||
|
assert(x + 1 == 4);
|
||||||
|
assert(2 + x == 5);
|
||||||
|
assert(x < 4);
|
||||||
|
}
|
||||||
|
|
||||||
private bool isCorrectCustomFloat(uint precision, uint exponentWidth, CustomFloatFlags flags) @safe pure nothrow @nogc
|
private bool isCorrectCustomFloat(uint precision, uint exponentWidth, CustomFloatFlags flags) @safe pure nothrow @nogc
|
||||||
{
|
{
|
||||||
// Restrictions from bitfield
|
// Restrictions from bitfield
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue