First note that mod(3^146,293)=292. For some reason, inputting mod(3^146,293) in Matlab returns 275. Inputting Math.pow(3,146) % 293 in JS returns 275. This same error occurs (as far as I can tell) every time. This leads me to believe I am missing something obvious but cannot seem to tell what.
Any help is much appreciated.
As discussed in the answers to this related question, MATLAB uses double-precision floating point numbers by default, which have limits on their resolution (i.e. the floating point relative accuracy, eps
). For example:
>> a = 3^146
a =
4.567759074507741e+69
>> eps(a)
ans =
7.662477704329444e+53
In this case, 3146 is on the order of 1069 and the relative accuracy is on the order of 1053. With only 16 digits of precision, a double can't store the exact integer representation of an arbitrary 70 digit integer.
An alternative in MATLAB is to use the Symbolic Toolbox to create symbolic numbers with a greater resolution. This gives you the answer you expect:
>> a = sym('3^146')
a =
4567759074507740406477787437675267212178680251724974985372646979033929
>> mod(a, 293)
ans =
292
In JavaScript, I have $scope.dtOptionsCandidate = DTOptionsBuilder.newOptions() .withColReorder() .withLightColumnFilter({ 1: {"type": "text"}, 2: {"type": "text"}, 3: ...
In JavaScript, I have $scope.dtOptionsCandidate = DTOptionsBuilder.newOptions() .withColReorder() .withLightColumnFilter({ 1: {"type": "text"}, 2: {"type": "text"}, 3: ...
I am using Firebase to authenticate users in our app using GoogleAuthProvider. But I don't want a new user to sign in if they are not already an authenticated user. If the user exists then sign them ...
I am using Firebase to authenticate users in our app using GoogleAuthProvider. But I don't want a new user to sign in if they are not already an authenticated user. If the user exists then sign them ...
I am looping through elements using jQuery like this: $(".myelement").each(function() { $element = $(this).closest(".panel").attr("id"); console.log($element); }); This is working correctly and ...
I am looping through elements using jQuery like this: $(".myelement").each(function() { $element = $(this).closest(".panel").attr("id"); console.log($element); }); This is working correctly and ...
I am getting problem to save my form data in the database. I am done small code on that which is shown below, when i enter data in form and click on my submit button it not work. $(".btn").click(...
I am getting problem to save my form data in the database. I am done small code on that which is shown below, when i enter data in form and click on my submit button it not work. $(".btn").click(...