-
Notifications
You must be signed in to change notification settings - Fork 683
Implemented Number.prototype.toFixed() #100
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
Conversation
@@ -312,6 +312,7 @@ extern int32_t ecma_number_to_int32 (ecma_number_t value); | |||
extern ecma_number_t ecma_int32_to_number (int32_t value); | |||
extern ecma_number_t ecma_uint32_to_number (uint32_t value); | |||
extern ecma_length_t ecma_number_to_zt_string (ecma_number_t num, ecma_char_t *buffer_p, ssize_t buffer_size); | |||
void ecma_number_to_zt_string_calc_number_params (ecma_number_t num, uint64_t *out_digits_p, int32_t *out_digits_num_p, int32_t *out_decimal_exp_p); |
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.
Shouldn't this be extern
like the others in this case?
@@ -932,7 +931,7 @@ ecma_number_to_zt_string_to_decimal (ECMA_NUMBER_CONVERSION_128BIT_INTEGER_ARG ( | |||
/** | |||
* Calculate s, n and k parameters for specified ecma-number according to ECMA-262 v5, 9.8.1, item 5 | |||
*/ | |||
static void |
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.
Are there any reason to remove static
?
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.
If the function stays static I cannot call it.
digits++; | ||
} | ||
|
||
/* 8. */ |
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.
General comment on this if/else
block. Functionally it seams OK, but I think we may introduce several helper functions to improve readability.
|
@@ -928,6 +928,27 @@ ecma_number_exp (ecma_number_t num) /**< valid finite number */ | |||
return sum; | |||
} /* ecma_number_exp */ | |||
|
|||
void | |||
ecma_number_round_last_digit (uint64_t &digits, int32_t num_digits, int32_t exponent, int32_t 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.
Could you, please, add comments to functions, and their arguments?
|
/** | ||
* Declare 128-bit integer. | ||
*/ | ||
#define ECMA_NUMBER_CONVERSION_128BIT_INTEGER(name) uint64_t name[4] = { 0, 0, 0, 0 } |
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.
Why do we need this in the header?
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.
I moved this part to share with ecma-helpers-number.cpp file.
@tczene could you, please, answer to all questions in the original review, it seems that some of notes were missed. |
@galpeter could you please recheck this issue? |
I've got no other comments. lgtm |
@egavrin anything to add? or it is okay to |
I see that with the changes there are two different functions, both performing conversion of number to decimal representation with decimal exponent. Do I understand it correctly? If it is correct, it seems that there are two functions that use Could we somehow extract the conversion algorithms used in both functions with lightweight part for FLOAT32-mode and precise part for FLOAT64-mode, putting them into separate helper routine, and just call the helper from both functions. In the case, we could also move What do you think about this? |
You're correct in that we're using 128bit integers in two functions, but the operations they perform are the opposite of each other. In Both of these functions already have a lightweight FLOAT32 part, and a precise FLOAT64 part. 128 bit integers are only used in case of FLOAT64 in both functions, so in my opinion their use is already fairly localized. We could move the macros for 128bit integers back to Also, if we are concerned with code size, we should probably consider changing some, or even all of the macros into helper functions, so that their impact on code size is less. |
@dbatyai, thank you very much for your explanation. |
@ruben-ayrapetyan, |
ecma_number_calc_params (ecma_number_t num, /**< ecma-number */ | ||
uint64_t *out_digits_p, /**< out: digits */ | ||
int32_t *out_digits_num_p, /**< out: number of digits */ | ||
int32_t *out_decimal_exp_p) /**< out: decimal exponent */ |
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.
@dbatyai, could you, please, rename the ecma_number_calc_params
function to ecma_number_to_decimal
, and the current ecma_number_to_decimal
to ecma_number_helper_binary_to_decimal
?
Could you, please, also update comments to the functions?
- new
ecma_number_to_decimal
:
/**
* Perform conversion of ecma-number to decimal representation with decimal exponent
*
* Note:
* The calculated values correspond to s, n, k parameters in ECMA-262 v5, 9.8.1, item 5:
* - s represents digits of the number;
* - k is the number of digits;
* - n is the decimal exponent.
*/
ecma_number_helper_binary_to_decimal
:
/**
* Perform conversion of 128-bit binary representation of number
* to decimal representation with decimal exponent.
*/
Thank you.
Thank you for making the changes. |
I've updated the patch. |
Do you have any other comments, or may we merge this? |
int32_t frac_digits = 0; | ||
|
||
/* 1. */ | ||
if (!ecma_is_value_undefined (arg)) |
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.
The check seems to be unnecessary, as ToNumber
returns NaN
for undefined
, and ToInt32
returns 0 for NaN
.
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai dbatyai.u-szeged@partner.samsung.com JerryScript-DCO-1.0-Signed-off-by: Tamas Czene tczene.u-szeged@partner.samsung.com
@ruben-ayrapetyan , updated. |
Looks good to me. |
seems good to me also. |
|
merged: 4836d3b |
JerryScript-DCO-1.0-Signed-off-by: László Langó llango.u-szeged@partner.samsung.com
JerryScript-DCO-1.0-Signed-off-by: Tamas Czene tczene.u-szeged@partner.samsung.com