-
Notifications
You must be signed in to change notification settings - Fork 676
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
Implement printing in the specified radix for Number.prototype.toString(). #207
Implement printing in the specified radix for Number.prototype.toString(). #207
Conversation
|
/* Add zero terminator. */ | ||
buff[buff_index] = '\0'; | ||
|
||
ecma_string_t* str = ecma_new_ecma_string ((ecma_char_t *) buff); |
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.
str_p
Please rebase to master |
I've rebased to master. Also, I'd like to ask your opinion on the buffer. Currently it's set to a fixed 1080 size, since this is the largest we would ever need. Of course, it would be better to use a dynamic buffer, but I don't know if it would be worthwhile to implement something like that only for this function. We could also try to use a smaller buffer and limit the string size. What do you think? |
…ng(). JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai [email protected]
@dbatyai, |
@ruben-ayrapetyan, could you please explain how exactly? The way I see it, |
@dbatyai, I see. You mean dynamically extensible buffer, but Could we somehow calculate the number of digits prior to buffer allocation, maybe using |
@ruben-ayrapetyan, Unfortunately we can't calculate the number of digits, because some finite fractions can become infinite when we convert them to a different radix. |
@dbatyai, yes, but in the case we anyway would truncate them to some finite number of digits. So, in the case, number of digits in output buffer is known, isn't it? |
@ruben-ayrapetyan, you're right, I'll calculate a buffer size with |
@ruben-ayrapetyan, I've tried to get buffer size with |
Can't digits number of fraction part be calculated from |
@ruben-ayrapetyan , |
assert((123400).toString(33) === "3ead"); | ||
assert((123400).toString(34) === "34pe"); | ||
assert((123400).toString(35) === "2upp"); | ||
assert((123400).toString(36) === "2n7s"); |
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.
It would be good to add some automated test, which runs through the 2 digit numbers for all 36 radix.
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.
+1
Continued here: #306 |
Depends on #100.
JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai [email protected]