I need to work with twitter IDs with a precision of 1. But e.g. for
91000000000000000 this exceeds the span where normal floating point
has a precision of 1. All I need to determine if a string representing
a number is larger or less another, and to increment or decrement said
string by 1. Doesn't need to be extremly fast so something that works
on strings like we humans calculate stuff would be nice.
- Axel
You are mistaken. JS integers are good for 51 decimal digits.
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
9e15 are
precise, but few decimal fractions are. Given this, arithmetic
is as exact as possible, but no more. Operations on integers
are exact if the true result and all intermediates are integers
within that range.
Albeit for integer operations its very possible to write a library
that can do arbitrary sizes, calculating overflows into the next
field, just hoped someone else did it already for node (or at least
javascript). Anyway Int64 is a good enough solution :-)
"// Let's do some math. Int64's behave like Numbers. (Sorry, Int64 isn't
// for doing 64-bit integer arithmetic (yet) - it's just for carrying
// around int64 values"
Ah well, without even simple math its useless, to carry around values
I can use strings just as well.
I found this http://jsfromhell.com/classes/bignumber but it has no License.
Anyway I found out that since I only have positive integers, I can
compare to string-numbers for being less with
function less(a, b) {
if (a.length < b.length) return true;
if (a.length > b.length) return false;
return a < b;
}
And thats actually all I needed, increment/decrement by 1 would have
made the algorithm more simple, but I can do without.
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en