D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 14842 - [REG 2.068-b2] approxEqual does not work with integers
Summary: [REG 2.068-b2] approxEqual does not work with integers
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 regression
Assignee: No Owner
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2015-07-28 08:23 UTC by lobo
Modified: 2017-07-19 17:43 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description lobo 2015-07-28 08:23:54 UTC
This works with dmd2.067.1 but with 2.068-b2 I get the errors shown below.


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."]
Comment 1 Илья Ярошенко 2015-07-28 09:58:41 UTC
This function should be restricted to floating point numbers, thought.
Comment 2 Daniel Kozak 2015-07-28 11:16:07 UTC
I agree with ilya: we should add deprecation message for non floating points numbers. This would be better than error
Comment 3 Kenji Hara 2015-07-29 04:09:10 UTC
Introduced in: https://github.com/D-Programming-Language/phobos/pull/3012
Comment 4 Walter Bright 2015-07-31 20:57:01 UTC
approxEqual is intended only for floating point arguments.
Comment 7 github-bugzilla 2015-08-04 22:04:48 UTC
Commits pushed to stable at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/bd8ed8c13cc4a73a182d8923122c17ba4ea5e524
fix Issue 14842 - [REG 2.068-b2] approxEqual does not work with integers

- promote any comparision with integers to real

https://github.com/D-Programming-Language/phobos/commit/de8896ae753bd491adba276fe6e653945334b580
Merge pull request #3525 from MartinNowak/fix14842

fix Issue 14842 - [REG 2.068-b2] approxEqual does not work with integers
Comment 8 github-bugzilla 2015-08-05 00:15:15 UTC
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/bd8ed8c13cc4a73a182d8923122c17ba4ea5e524
fix Issue 14842 - [REG 2.068-b2] approxEqual does not work with integers

https://github.com/D-Programming-Language/phobos/commit/de8896ae753bd491adba276fe6e653945334b580
Merge pull request #3525 from MartinNowak/fix14842
Comment 9 github-bugzilla 2017-07-19 17:43:39 UTC
Commits pushed to dmd-cxx at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/bd8ed8c13cc4a73a182d8923122c17ba4ea5e524
fix Issue 14842 - [REG 2.068-b2] approxEqual does not work with integers

https://github.com/dlang/phobos/commit/de8896ae753bd491adba276fe6e653945334b580
Merge pull request #3525 from MartinNowak/fix14842