Skip to content

Conversation

@mislavn
Copy link

@mislavn mislavn commented Dec 11, 2018

Hi,

I implemented the eth_convert function described in #97, I tried to use as much as possible the uint256_t functions, but now the code is a bit clunky and I'm not sure if I should simply convert the number to a string and simply add a . and move the number as strings around.

Signed-off-by: Mislav Novakovic [email protected]

eth/web3.c Outdated

// add zeros
if (from >= to) {
set256_uint64(&power, pow(10, (int) from - (int) to));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can't really use pow() here since embedded systems can't use floats

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the custom pow function can't be built without using uint128_t (2 ^ 64 < 30) I used simple string manipulation for the eth_convert function, it's more efficient.

Copy link
Contributor

@pcppcp pcppcp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, please fix the magic numbers and add some test where the function is expected to fail and it's good to merge.

eth/web3.c Outdated
return -1;
}
// move numbers
for (i = len + 1 + 1; i > len - shift; --i) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nitpick - could you replace magic numbers in string length calculation with defines? It will make it easier to read and understand.

i.e. here it would look like for (i = len + DECIMAL_POINT + SOMETHING; i > len - shift; --i)

Signed-off-by: Mislav Novakovic <[email protected]>
@mislavn
Copy link
Author

mislavn commented Dec 20, 2018

@pcppcp do you want me to do any other changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants