| 46 | |
| 47 | template<class A, class B> |
| 48 | ExecStatus |
| 49 | Pow<A,B>::post(Home home, A x0, B x1, int n) { |
| 50 | if (n == 0) { |
| 51 | if ((x0.min() == 0.0) && (x0.max() == 0.0)) return ES_FAILED; |
| 52 | GECODE_ME_CHECK(x1.eq(home,1.0)); |
| 53 | return ES_OK; |
| 54 | } |
| 55 | |
| 56 | GECODE_ME_CHECK(x1.eq(home,pow(x0.domain(),n))); |
| 57 | if ((x1.min() == 0.0) && (x1.max() == 0.0)) { |
| 58 | GECODE_ME_CHECK(x1.eq(home,0.0)); |
| 59 | return ES_OK; |
| 60 | } |
| 61 | |
| 62 | if ((n % 2) == 0) { |
| 63 | if (x0.min() >= 0) |
| 64 | GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),n))); |
| 65 | else if (x0.max() <= 0) |
| 66 | GECODE_ME_CHECK(x0.eq(home,-nroot(x1.domain(),n))); |
| 67 | else |
| 68 | GECODE_ME_CHECK(x0.eq(home, |
| 69 | hull( |
| 70 | nroot(x1.domain(),n), |
| 71 | -nroot(x1.domain(),n) |
| 72 | ) |
| 73 | )); |
| 74 | } else { |
| 75 | GECODE_ME_CHECK(x0.eq(home,nroot(x1.domain(),n))); |
| 76 | } |
| 77 | |
| 78 | if (!x0.assigned()) (void) new (home) Pow<A,B>(home,x0,x1,n); |
| 79 | return ES_OK; |
| 80 | } |
| 81 | |
| 82 | template<class A, class B> |
| 83 | forceinline |