broofa/node-int64

Need way to get the lossy representation

wadey opened this issue · 6 comments

I like the default behavior of returning Infinity, but I think there needs to still be a way to get the lossy number representation out. I was thinking you could either let valueOf take in a boolean parameter like valueOf(lossy) (defaulting to false), or maybe add another function called num.lossyValueOf that Int64 would call internally for .valueOf with the extra validation at the end. Thoughts?

I'd rather not mess with toValue's signature, since that method has special meaning. How about "num.toNumber()" - the semantic being, "cast this to a native Number instance"?

num.toNumber() sounds perfect to me. Want a pull request or do you have it?

'Just committed it. Take a look and let me know if that works for you. Apologies for all the trivial whitespace clutter in the diff - I'm using an improved VIM indent script and decided to clean up a bit. :)

If it's okay, I'll go ahead and publish to npm.

oh, and it's "i64value.toNumber(true)" to get imprecise version.

The patch looks good to me. Thanks for the quick turnaround, I look forward to making node-thrift depend on this.

published