samedi 19 août 2017

Emulate JavaScript addition errors with large integers in Python

kind of an odd request: I'm parsing API parameters from a website. The parameters are being processed by JavaScript on the website to make a request to an API server. The parameters are chosen in a way, where they are added up to form an other parameter (see parameter c):

var c = 97210102839047737+67973223506388211;
[...]

var plans = new Array();
$.ajax({

  url: 'info/?c='+c,
  dataType: 'json',

  success: function(data) {
[...]
  }
});

JavaScript seems to have problems with large integers and fails to add them correctly. I want to emulate this behaviour with python, since I want to automate the extraction and request process. Adding the two numbers with javascript yields:

console.log(97210102839047737+67973223506388211)
VM109:1 165183326345435970

While Python correctly adds it to:

>>> print(97210102839047737+67973223506388211)
165183326345435948

Any recommendations how I can emulate this error inside of python?

Thanks a bunch! :)




Aucun commentaire:

Enregistrer un commentaire