www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2973] New: std.math.pow(int, int), etc.

reply d-bugmail puremagic.com writes:
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: -------
May 13 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2973


ZHOU Zhenyu <rinick gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rinick gmail.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.
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: -------
Jul 21 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2973


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei metalanguage.com





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: -------
Jul 21 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2973






---
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: -------
Jul 21 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2973






20:15:20 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.
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: -------
Jul 21 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2973







 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: -------
Jul 21 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2973


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au





 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: -------
Aug 11 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
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: -------
Oct 11 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2973


David Simcha <dsimcha yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |WONTFIX



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: -------
Oct 18 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2973




13:06:15 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.
Thanks for following through. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Oct 18 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2973


ZY Zhou <rinick gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|WONTFIX                     |



Now we have power operator.
It will be very confusing that 3.0^^3 works but 3^^3 doesn't. Most people would
think ^^ in D is just like ** in python.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 04 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2973


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED



FIXED: 3^^3 works in DMD 2.040.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 12 2010