Why approxEqual not working for integers in dmd 2068-b2

Daniel Kozák via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jul 27 23:50:53 PDT 2015


On Tue, 28 Jul 2015 02:16:56 +0000
"lobo" <swamplobo at gmail.com> wrote:

> Hi all,
> 
> I have a bunch of unittests for template code taking any numeric 
> type. Because I'm lazy I just use the approxEqual for both 
> floating point and integer comparisons in these tests.
> 
> In DMD 2067.1 everthing compiled OK but in 2068-b2 I get the 
> errors shown at the end of this post for integer types.
> 
> 
> I'd like to know if it is OK to use approxEqual like I am in 
> unittests and why approxEqual was changed, if it was intentional, 
> for learning more about good use of D language
> 
> 
> Thanks,
> lobo
> 
> 
> 
> Test code:
> ---
> void main() {
> 
>      int a = 10;
>      assert(approxEqual(10, a));
> 
> }
> ---
> Errors:
> 
> src/phobos/std/math.d(6718): Error: std.math.fabs called with 
> argument types (int) matches both:
> src/phobos/std/math.d(3415):     std.math.fabs(real x)
> and:
> /src/phobos/std/math.d(3421):     std.math.fabs(float x)
> /src/phobos/std/math.d(6725): Error: std.math.fabs called with 
> argument types (int) matches both:
> /src/phobos/std/math.d(3415):     std.math.fabs(real x)
> and:
> /src/phobos/std/math.d(3421):     std.math.fabs(float x)
> /src/phobos/std/math.d(6726): Error: std.math.fabs called with 
> argument types (int) matches both:
> /src/phobos/std/math.d(3415):     std.math.fabs(real x)
> and:
> /src/phobos/std/math.d(3421):     std.math.fabs(float x)
> /src/phobos/std/math.d(6736): Error: template instance 
> std.math.approxEqual!(int, int, double) error instantiating
> hack.d(13):        instantiated from here: approxEqual!(int, int)
> Failed: ["dmd", "-v", "-o-", "hack.d", "-I."]
> ---

I would say it is a compiler bug.

consider this:

bool some(real x, real y) {
	return true;
}

bool some(float x, float y) {
	return true;
}

void main() {
	some(4.0L, 4.0L); // ok
	some(4L,4L); // this should implicit convert to real,real
}

but:

//m.d(11): Error: m.some called with argument types (long, long) matches
both: //m.d(1):     m.some(real x, real y) //and: //m.d(5):
m.some(float x, float y

It is in confrontance with TDPL p.44 figure 2.3


More information about the Digitalmars-d-learn mailing list