-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shorter encoding for numbers (breaking change) #9
base: master
Are you sure you want to change the base?
Conversation
I chose '_' as the end character, since it's higher than numbers, and makes the output more readable. |
Yes indeed, numbers where encoded as "fixed length record". This was needed for the digit flipping trick to work on negative numbers. Adding a char superior to 9 to the mantissa of a negative number should work, that's a nice idea ! |
codec/number.js
Outdated
@@ -14,8 +16,8 @@ exports.encode = function (number) { | |||
|
|||
var splitScientificNotation = number.toExponential().split('e'); | |||
var exponent = Number(splitScientificNotation[1]) + 500; | |||
var mantissa = splitScientificNotation[0] + (splitScientificNotation[0].indexOf('.') === -1 ? '.' : '') + '0'.repeat(20); | |||
var encoded = 'E' + padStart(String(exponent), 3) + 'M' + String(mantissa); | |||
var mantissa = splitScientificNotation[0] + (splitScientificNotation[0].indexOf('.') === -1 ? '.' : '')//+ '0'.repeat(20); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the zeros are not appended anymore, there is no need to add a '.' after the mantissa if it is a round number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
Is there any desire to merge this compact change ? |
I went ahead and publishes this breaking change by making a new package and naming it |
Oh I can't remember if there was something still wrong with this? Did all
the tests pass etc? Possibly I just forgot about it?
…On Wed, Mar 11, 2020, 04:20 Jake Verbaten ***@***.***> wrote:
I went ahead and publishes this breaking change by making a new package
and naming it charwise-compact (
https://github.com/Raynos/charwise-compact ).
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#9?email_source=notifications&email_token=AAB7KLXWURQBLJ4NYXGGUODRGZLDNA5CNFSM4E7REMN2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOL3JTI#issuecomment-597144781>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB7KLTHF4OJCV6OTWQT3WDRGZLDNANCNFSM4E7REMNQ>
.
|
From what i remember, everything was ok. |
I suspect you either forgot about this or did not want to do any breaking changes or migrations of the key space in leveldb. |
@@ -6,6 +6,8 @@ | |||
// We endpad mantissa with enough zero to exceed mantissa precision. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment is for the old code...
You have reviewed your own pull request. This is pretty meta. |
@PaulBlanche I realized that numbers are encoded with a huge amount of precision.
2 is encoded as
FE500M2.00000000000000000000
... that seems unnecessary to me?I removed that, and noticed it failed on the close random number tests
so I tried just appending a number that we know is higher than 9, but only on negative numbers. This seems to work, tests pass.
cw.encode(-1)+'a' > cw.encode(-1.00000001)+'a'