Opened 9 years ago

Closed 9 years ago

#8798 closed Bugs (fixed)

pow(cpp_dec_float_type(0), cpp_dec_float_type(n)) != 0 for n > 1

Reported by: Jan Bouwer <JBouwer@…> Owned by: John Maddock
Milestone: To Be Determined Component: multiprecision
Version: Boost Development Trunk Severity: Problem
Keywords: Cc:

Description

The overload of 'pow' taking both arguments of number<cpp_dec_float<...>> gives a wrong answer when the base == 0 and the exponent > 1.

eg.

using T = cpp_dec_float_50;
assert( pow(T(0), T(2)) == 0 ); // Failure

Tested against svn #84980 with clang (Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)) target: x86_64-apple-darwin12.4.0 with: -std=c++11 -stdlib=libc++

Attachments (2)

boost_multiprecision_power_demo.cpp (2.7 KB ) - added by Jan Bouwer <JBouwer@…> 9 years ago.
Demonstration of the error
boost_multiprecision_power_demo.2.cpp (2.7 KB ) - added by Jan Bouwer <JBouwer@…> 9 years ago.
Demonstration of the error - without annoyance, please remove previous

Download all attachments as: .zip

Change History (4)

by Jan Bouwer <JBouwer@…>, 9 years ago

Demonstration of the error

by Jan Bouwer <JBouwer@…>, 9 years ago

Demonstration of the error - without annoyance, please remove previous

comment:1 by Jan Bouwer <JBouwer@…>, 9 years ago

Output of the attached code:

pow(0, 0) = 1
pow(0, 1) = 0
pow(0, 2) = 0
pow(1, 0) = 1
pow(1, 1) = 1
pow(1, 2) = 1
pow(2, 0) = 1
pow(2, 1) = 2
pow(2, 2) = 4
pow(0, 0) = 1
pow(0, 1) = 0
pow(0, 2) = 1 - Unexpected!
pow(1, 0) = 1
pow(1, 1) = 1
pow(1, 2) = 1
pow(2, 0) = 1
pow(2, 1) = 2
pow(2, 2) = 4
pow(0, 0) = 1
pow(0, 1) = 0
pow(0, 2) = 1 - Unexpected!
pow(1, 0) = 1
pow(1, 1) = 1
pow(1, 2) = 1
pow(2, 0) = 1
pow(2, 1) = 2
pow(2, 2) = 4
pow(0, 0) = 1
pow(0, 1) = 0
pow(0, 2) = 1 - Unexpected!
pow(1, 0) = 1
pow(1, 1) = 1
pow(1, 2) = 1
pow(2, 0) = 1
pow(2, 1) = 2
pow(2, 2) = 4

comment:2 by John Maddock, 9 years ago

Resolution: fixed
Status: newclosed

(In [84997]) Fix bug in eval_pow that causes 0N to be none-zero. Fixes #8798.

Note: See TracTickets for help on using tickets.