www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why approxEqual not working for integers in dmd 2068-b2

reply "lobo" <swamplobo gmail.com> writes:
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."]
---
Jul 27 2015
next sibling parent reply Daniel =?UTF-8?B?S296w6Fr?= <kozzi dlang.cz> writes:
On Tue, 28 Jul 2015 02:16:56 +0000
"lobo" <swamplobo 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
Jul 27 2015
parent Daniel =?UTF-8?B?S296w6Fr?= <kozzi dlang.cz> writes:
On Tue, 28 Jul 2015 08:50:53 +0200
Daniel Koz=C3=A1k <kozzi dlang.cz> wrote:

=20
 On Tue, 28 Jul 2015 02:16:56 +0000
 "lobo" <swamplobo gmail.com> wrote:
=20
 I would say it is a compiler bug.
=20
 consider this:
=20
 bool some(real x, real y) {
 	return true;
 }
=20
 bool some(float x, float y) {
 	return true;
 }
=20
 void main() {
 	some(4.0L, 4.0L); // ok
 	some(4L,4L); // this should implicit convert to real,real
 }
=20
 but:
=20
 //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
=20
 It is in confrontance with TDPL p.44 figure 2.3
OTOH D has same behaviour as C++
Jul 28 2015
prev sibling parent reply Daniel =?UTF-8?B?S296w6Fr?= <kozzi dlang.cz> writes:
On Tue, 28 Jul 2015 02:16:56 +0000
"lobo" <swamplobo 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."]
 ---
Even if this will be considered as non compiler bug, it is a regression on phobos side and should be addressed. So please fill a bug report on http://issues.dlang.org
Jul 28 2015
parent "lobo" <swamplobo gmail.com> writes:
On Tuesday, 28 July 2015 at 07:42:32 UTC, Daniel Kozák wrote:
 Even if this will be considered as non compiler bug, it is a 
 regression on phobos side and should be addressed. So please 
 fill a bug report on http://issues.dlang.org
done, thanks https://issues.dlang.org/show_bug.cgi?id=14842
Jul 28 2015