| 1 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 2 | Real ReaPower(Real x, Real y) |
|---|
| 3 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 4 | { |
|---|
| 5 | Case |
|---|
| 6 | ( |
|---|
| 7 | EQ(y,0), 1, |
|---|
| 8 | And(EQ(x,0), GT(y,0)), 0, |
|---|
| 9 | And(EQ(x,0), LT(y,0)), 1/0, |
|---|
| 10 | And(NE(x,0), NE(y,0)), Sign(x)*(Abs(x)^y) |
|---|
| 11 | ) |
|---|
| 12 | }; |
|---|
| 13 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 14 | PutDescription("Calcula la potencia y de un numero x. La funcion ^ no retorna |
|---|
| 15 | correctamente el valor para x <= 0 e y no entero o 0, en las versiones |
|---|
| 16 | 1.1.8 y 1.1.9", |
|---|
| 17 | ReaPower); |
|---|
| 18 | ////////////////////////////////////////////////////////////////////////////// |
|---|
| 19 | |
|---|
| 20 | Set TestReaPower = |
|---|
| 21 | { |
|---|
| 22 | Set xSet = SetOfReal(3, 0, -3); |
|---|
| 23 | Set ySet = SetOfReal(3, 4/3, 3/2, 1/2, 1/3, 0, -1/3, -1/2, -3/2, -4/3, -3); |
|---|
| 24 | |
|---|
| 25 | Set data = EvalSet(CartProd(xSet, ySet), Set(Set reg) |
|---|
| 26 | { |
|---|
| 27 | Real x = reg[1]; |
|---|
| 28 | Real y = reg[2]; |
|---|
| 29 | |
|---|
| 30 | Real pow = ReaPower(x,y); |
|---|
| 31 | Real ori = x^y; |
|---|
| 32 | SetOfReal(x, y, pow, ori) |
|---|
| 33 | }); |
|---|
| 34 | |
|---|
| 35 | Set header = SetOfText("x", "y", "ReaPower(x, y)", "x^y"); |
|---|
| 36 | SetOfSet(header)<<data |
|---|
| 37 | }; |
|---|