The ctor accepts any type that is an integral. But then uses the type of the integral to do the math. The entire constructor is:
this(T)(const T i) if (isIntegral!T)
{
value = i * factor;
}
Consider the value int.max as a parameter to a Fixed!2 struct. This results in assigning the value int.max * 100, which ends up being -100. However, a Fixed!2 based on long is perfectly capable of storing the correct value of 214_748_364_700.
Not only that, but even if the incoming type is larger than the stored type, it's not going to compile. I think the ctor should simply accept a V instead of a templated type. That should fix this bug.
The ctor accepts any type that is an integral. But then uses the type of the integral to do the math. The entire constructor is:
Consider the value
int.max
as a parameter to aFixed!2
struct. This results in assigning the valueint.max * 100
, which ends up being -100. However, aFixed!2
based onlong
is perfectly capable of storing the correct value of214_748_364_700
.Not only that, but even if the incoming type is larger than the stored type, it's not going to compile. I think the ctor should simply accept a V instead of a templated type. That should fix this bug.