stedolan/jq — pull request #234 by DRMacIver (2013-12-09 01:37:11+00:00)
Title: Integer representations for numbers

This pull request is decidedly speculative and shouldn't be considered ready to merge. I'm mostly mostly putting it out there to see if you were in principle interested in this branch or whether I should just consider it an interesting experiment in learning jq internals.

Basic idea: Numbers can be represented as either integers or doubles. We try to keep numbers as integers but fall back to doubles where this would produce bad results.

Semantics: Two numbers are equal if either they are both doubles or they both represent the same integer (so 1.0 == 1 but 288230376151711743 != 288230376151711744 despite being the same double). Otherwise, when operating on pairs of integers, treat them as integers, else convert integers to doubles.

This is mainly to address issues like https://github.com/stedolan/jq/issues/218 and https://github.com/stedolan/jq/issues/178.

Problems with this branch at present:

* Does not correctly deal with overflows in addition and multiplication (where these occur we should fall back to double arithmetic)
* The parsing and printing code are quite gross
* I don't know if you even consider the feature desirable.