IT ALREADY IS IMPLEMENTED, since you can use vpi, as found on the file exchange. This what i need to calculate modexp(base,exp,mod) ![]() ![]() So MATLAB goes out of its way to do some magic with the floating-point results. This suggests that when x/y is close to an integer then it's rounded first, rather than being truncated like in python. Within roundoff error of an integer, then n is that integer. If y is not an integer and the quotient x./y is Now here's help mod from MATLAB: MOD(x,y) returns x - floor(x./y).*y if y ~= 0, carefully computed toĪvoid rounding error. One can easily prove that these two numbers are indeed the same within double precision: > print(6/Decimal('0.05') - 6/Decimal(0.05)) The first number is what you'd first get with 6/0.05, but the number 119.9999999999999933386618522 gets rounded to the nearest number representable with double precision, and this is 120. print(6/Decimal(0.05)) # exactly approximate Some proof: > from decimal import Decimal However, it's ever so slightly smaller than 120, so explicit floor division will truncate that number to 119 before it could be normalized to 120.0. within the resolution of double precision) that it gets rounded to 120.0. The floating-point result of 6/0.05 is close enough to 120 (i.e. This is the core of the problem, in python: > 6/0.05 = 120
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |