开发者

Fastest way to find Quotient by Dividing two Number

I have to do some logic based on the following implementation.

I have a big number upto 36 Digits e.g. 913695089923267549815145223638290430 (randomly generated by different app). I need to divide it by any number smaller in length say 70368844197664;(randomly generated by different app) Suppose i get quotient as 19956694.3256

For my code only last digit of quotient before decimal (i.e. 4) is important. The objective is to check whether the quotient is even or odd and if possible value of last digit too.

I cannot use simple DB functions like modulus or division as it is very time consuming. Is there any faster efficient way? 开发者_高级运维Any suggestions will be highly appreciated.

Thank you so much.

Regards Neeraj


What you want to do is pretty much the definition of "modulo arithmetic". If the built-in arithmetic in your database can't do the calculation fast enough, I'm not sure what you could do to improve that short of writing your own database engine or buying higher-powered hardware.

Is the problem really the speed of the arithmetic, or is it record retrieval or indexing? I mean, if you're saying something like:

select ... whatever ... from table1 join table2 using (someid)
where (table1.q / table2.d) % 10 = 4

and you don't have an index on the function (table1.q / table2.d ) % 10, this would require the db to read every record, perform the calculation, and then pick out those that give the right answer. Your problem might not be arithmetic, but indexing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜