What is a concise way to test if floating point value is integral?

Paul Jurczak pauljurczak at yahoo.com
Wed Aug 28 23:00:33 PDT 2013


On Thursday, 29 August 2013 at 05:47:43 UTC, Paul Jurczak wrote:
> I'm writing this rather ugly:
>
> sqrt(cast(float)D) != round(sqrt(cast(float)D)
>
> line and I'm looking for more concise notation without 
> introducing a meaningless variable to hold expression being 
> tested. Is there an equivalent of std.math.trunc(), which would 
> return fractional portion instead, maybe frac()?

I defined a helper function:

bool isIntegral(T)(T x) {return x == round(x);}

but is there something in D libraries to give me this 
functionality?


More information about the Digitalmars-d-learn mailing list