-
Notifications
You must be signed in to change notification settings - Fork 16
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
add ethereum conversion function #155
base: master
Are you sure you want to change the base?
Conversation
eth/web3.c
Outdated
|
||
// add zeros | ||
if (from >= to) { | ||
set256_uint64(&power, pow(10, (int) from - (int) to)); |
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.
you can't really use pow()
here since embedded systems can't use floats
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 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.
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.
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) { |
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.
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]>
@pcppcp do you want me to do any other changes? |
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]