-
Notifications
You must be signed in to change notification settings - Fork 215
some linting #436
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
some linting #436
Conversation
|
uL suffix is wrong for small digits (MP_16BIT). |
|
reworked |
demo/test.c
Outdated
| for (i = 0; i < 1000; ++i) { | ||
| int tmp = rand_int(); | ||
| double dbl = (double)tmp * rand_int() + 1; | ||
| double dbl = (double)((tmp * rand_int()) + 1); |
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 chance is quite high that tmp * rand_int() overflows, which just happend in Travis. If you want to add parentheses it needs to be more something like
double dbl = ( (double)tmp * rand_int() ) + 1.0;or maybe even cast rand_int() too and do a
double dbl = (double)tmp * (double)rand_int() + 1.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.
@czurnieden fixed with another way
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.
fixed with another way
Travis moans: "warning: cast from function call of type ‘int’ to non-matching type ‘double’"
rand_int() -> rand_double()?
static double rand_double(void)
{
uint64_t x;
/* Doesn't work with feeding a float directly? */
if (s_mp_rand_source(&x, sizeof(x)) != MP_OKAY) {
fprintf(stderr, "s_mp_rand_source failed\n");
exit(EXIT_FAILURE);
}
return (double)x;
}And then:
double tmp = rand_double();
double dbl = (tmp * rand_double()) + 1.0;But there is a change that this produces NaN, +-inf, and denormal numbers, we would need to weed them out in rand_double().
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 think that a rand_double() could help.
But at this time, I'll remove this part of the commit.
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.
But there is a chance that this produces
NaN,+-inf, and denormal numbers, we would need to weed them out inrand_double().
No it wouldn't, because it is just a cast; we use the value not the bitpattern.
Sorry, my fault.
No description provided.