Thread overview | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
May 13, 2009 [Issue 2973] New: std.math.pow(int, int), etc. | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=2973 Summary: std.math.pow(int, int), etc. Product: D Version: 2.030 Platform: PC OS/Version: Windows Status: NEW Severity: enhancement Priority: P2 Component: Phobos AssignedTo: bugzilla@digitalmars.com ReportedBy: dsimcha@yahoo.com std.math should have a function for efficiently and accurately computing int^int, int ^ uint, etc. Casting to floating point is not a good solution b/c you lose performance and, in some cases, precision. Furthermore, this would be dead simple to implement. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 21, 2009 [Issue 2973] std.math.pow(int, int), etc. | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsimcha@yahoo.com | http://d.puremagic.com/issues/show_bug.cgi?id=2973 ZHOU Zhenyu <rinick@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |rinick@gmail.com --- Comment #1 from ZHOU Zhenyu <rinick@gmail.com> 2009-07-21 01:02:35 PDT --- (In reply to comment #0) > std.math should have a function for efficiently and accurately computing int^int, int ^ uint, etc. Casting to floating point is not a good solution b/c you lose performance and, in some cases, precision. Furthermore, this would be dead simple to implement. agree int^uint and long^uint are useful. but int^int is not necessary, because: int a = pow(2,-1); this doesn't make any sense. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 22, 2009 [Issue 2973] std.math.pow(int, int), etc. | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsimcha@yahoo.com | http://d.puremagic.com/issues/show_bug.cgi?id=2973 Andrei Alexandrescu <andrei@metalanguage.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |andrei@metalanguage.com --- Comment #2 from Andrei Alexandrescu <andrei@metalanguage.com> 2009-07-21 19:19:38 PDT --- We currently have: pure nothrow F pow(F)(F x, uint n) if (isFloatingPoint!(F)); pure nothrow F pow(F)(F x, int n) if (isFloatingPoint!(F)); F pow(F)(F x, F y) if (isFloatingPoint!(F)); I think we're in good shape. We could add overloads for raising integrals to unsigned powers but I fear confusion due to wraparound. The magnitudes of exponents for which efficiency could become an issue are also those that would wraparound the result. If no compelling arguments come up, I'll close this soon. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 22, 2009 [Issue 2973] std.math.pow(int, int), etc. | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsimcha@yahoo.com | http://d.puremagic.com/issues/show_bug.cgi?id=2973 --- Comment #3 from David Simcha <dsimcha@yahoo.com> 2009-07-21 19:55:36 PDT --- Couldn't you just stick an assert in there to make sure it doesn't wrap around? I haven't tested, but I would think that even in debug mode, this would be faster than using the float version. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 22, 2009 [Issue 2973] std.math.pow(int, int), etc. | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsimcha@yahoo.com | http://d.puremagic.com/issues/show_bug.cgi?id=2973 --- Comment #4 from Andrei Alexandrescu <andrei@metalanguage.com> 2009-07-21 20:15:20 PDT --- (In reply to comment #3) > Couldn't you just stick an assert in there to make sure it doesn't wrap around? > I haven't tested, but I would think that even in debug mode, this would be > faster than using the float version. 1. Please test. What powers are you looking at? For most bases and most exponents the result will go off range. 2. I prefer returning a floating point number instead of attempting to return an integer and failing dynamically, all for a doubtful speed benefit. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
July 22, 2009 [Issue 2973] std.math.pow(int, int), etc. | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsimcha@yahoo.com | http://d.puremagic.com/issues/show_bug.cgi?id=2973 --- Comment #5 from ZHOU Zhenyu <rinick@gmail.com> 2009-07-21 23:22:10 PDT --- (In reply to comment #4) > What powers are you looking at? For most bases and most exponents the result will go off range. long a = foo(); long b = a * a * a; I don't want to call foo() again. So I have to define one more variable just because pow doesn't accept integer. (In fact, I have a longPow function and I use it from time to time) -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
August 11, 2009 [Issue 2973] std.math.pow(int, int), etc. | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsimcha@yahoo.com | http://d.puremagic.com/issues/show_bug.cgi?id=2973 Don <clugdbug@yahoo.com.au> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |clugdbug@yahoo.com.au --- Comment #6 from Don <clugdbug@yahoo.com.au> 2009-08-11 04:58:06 PDT --- > Casting to floating point is not a good solution b/c > you lose performance and, in some cases, precision. Are you sure? Performance: Floating point multiplication is typically the same speed or faster than integer multiplication on most CPUs from the past 15 years. On most Intel CPUs, integer multiplication is actually done in the floating point unit. Precision: You'll only lose precision if the base is greater than the 1/real.epsilon. For an 80-bit real, this means precision is lost only when the result is exactly equal to ulong.max. And the only time that can happen is with pow(ulong.max, 1). (because ulong.max is divisible by 5, but not by 25). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 11, 2009 [Issue 2973] std.math.pow(int, int), etc. | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsimcha@yahoo.com | http://d.puremagic.com/issues/show_bug.cgi?id=2973 Andrei Alexandrescu <andrei@metalanguage.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED AssignedTo|nobody@puremagic.com |andrei@metalanguage.com -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 18, 2009 [Issue 2973] std.math.pow(int, int), etc. | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsimcha@yahoo.com | http://d.puremagic.com/issues/show_bug.cgi?id=2973 David Simcha <dsimcha@yahoo.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|ASSIGNED |RESOLVED Resolution| |WONTFIX --- Comment #7 from David Simcha <dsimcha@yahoo.com> 2009-10-18 07:51:24 PDT --- Since I filed this one and I'm thoroughly convinced now that it's not necessary and noone else seems to want it, I'm resolving it as WONTFIX. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 18, 2009 [Issue 2973] std.math.pow(int, int), etc. | ||||
---|---|---|---|---|
| ||||
Posted in reply to dsimcha@yahoo.com | http://d.puremagic.com/issues/show_bug.cgi?id=2973 --- Comment #8 from Andrei Alexandrescu <andrei@metalanguage.com> 2009-10-18 13:06:15 PDT --- (In reply to comment #7) > Since I filed this one and I'm thoroughly convinced now that it's not necessary and noone else seems to want it, I'm resolving it as WONTFIX. Thanks for following through. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation