Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Ashley Nguyen

Suspended
Original poster
Oct 23, 2014
2
0
Hi,

I am using VecLib in the Accelerate framework to implement a C++ class for large integer calculations.

After some testing, I discovered that division functions were not always calculating the correct result.

The following code shows what happens:


Code:
Code:
vU512 A,B,C,Q,R;
       
memset(&A,0,sizeof(vU512));
memset(&B,0,sizeof(vU512));
       
A.s.LSW = 1;
B.s.LSW = 3;
       
for (int64_t k=1; k<129; k++)
{
     vU512HalfMultiply(&A,&B,&C);
           
     A = C;
           
     vU512Divide(&C,&B,&Q,&R);
           
     assert(R.s.LSW == 0);
}

When the counter k reaches 81 the assert fails, indicating that the division did not calculate correct.

(the preceeding instruction multiplies with B and the next divides by B, and this should give a remainder of 0)

I have noticed that the error occurs when the number C becomes larger than 2^128.

I am not sure what to think about this:

- Did I make a mistake and coded wrong.

- Is the problem related to an older Mac

- Is Apple frameworks doing wrong calculations

Hope that someone can clarify this.

Kind regards
 
Last edited by a moderator:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.