Movement against float.init being nan
bauss
jacobbauss at gmail.com
Tue Aug 23 11:17:49 UTC 2022
On Tuesday, 23 August 2022 at 08:03:44 UTC, jordan4ibanez wrote:
> I have seen how polar people's view points are on this issue.
> This is why I have created a library to solve this. Now people
> who wish floating points init to 0 can have it!
>
> https://code.dlang.org/packages/j_init
The problem with this is metaprogramming will break because you
will need to handle your Float/Double type apart from
float/double.
Ex.
```d
// This function might not be something we can modify
auto add(Number)(Number x, Number y) if (is(Number == float) ||
is(Number == double)) {
return x + y;
}
void main()
{
Float f1;
Float f2;
// Error:
// writeln(add(f1, f2));
// To fix it:
writeln(add(cast(float)f1, f2));
}
```
By using your struct implementation then one has to handle those
two types as well, otherwise it will break from stuff like shown
above.
So there's really no actual good way to override default
initialization values.
More information about the Digitalmars-d
mailing list