Macaulay2 Engine
Loading...
Searching...
No Matches

◆ TEST() [7/7]

TEST ( ARingRR ,
subtract  )

Definition at line 139 of file ARingRRTest.cpp.

140{
141 M2::ARingRR R;
142 auto nbits = R.get_precision();
144 M2::ARingRR::ElementType a, b, c, e;
145 R.init(a);
146 R.init(b);
147 R.init(c);
148 R.init(e);
149 for (int i = 0; i < ntrials; i++)
150 {
151 // test: (a-b) + (b) == a
152 gen.nextElement(a);
153 gen.nextElement(b);
154 R.subtract(c, a, b);
155 R.add(e, c, b); // should be a
156 EXPECT_TRUE(almostEqual(R, nbits - 2, a, e));
157 R.mult(e, a, b);
158 // std::cout << e-a*b << " " << e << " " << a << " " << b << std::endl;
159 R.subtract_multiple(e, a, b);
160 // EXPECT_TRUE(R.is_zero(e)); // this is not necessarily zero (it is with
161 // MPFR)
162 EXPECT_TRUE(almostEqual(R, nbits - 2, e, 0));
163 }
164 R.clear(e);
165 R.clear(c);
166 R.clear(b);
167 R.clear(a);
168}
bool almostEqual(const M2::ARingRR &R, unsigned long nbits, const M2::ARingRR::ElementType &a, const M2::ARingRR::ElementType &b)
const int ntrials
Definition ARingTest.hpp:42
void init(ElementType &result) const
Definition aring-RR.hpp:124
void mult(ElementType &result, const ElementType &a, const ElementType &b) const
Definition aring-RR.hpp:203
elem ElementType
Definition aring-RR.hpp:68
void subtract_multiple(ElementType &result, const ElementType &a, const ElementType &b) const
Definition aring-RR.hpp:196
static void clear(ElementType &result)
Definition aring-RR.hpp:128
unsigned long get_precision() const
Definition aring-RR.hpp:73
void add(ElementType &result, const ElementType &a, const ElementType &b) const
Definition aring-RR.hpp:175
void subtract(ElementType &result, const ElementType &a, const ElementType &b) const
Definition aring-RR.hpp:189
aring-style adapter for double-precision real numbers.
Definition aring-RR.hpp:62

References M2::ARingRR::add(), almostEqual(), M2::ARingRR::clear(), M2::ARingRR::get_precision(), M2::ARingRR::init(), M2::ARingRR::mult(), ARingElementGenerator< RingType >::nextElement(), ntrials, M2::ARingRR::subtract(), subtract(), and M2::ARingRR::subtract_multiple().