Skip to content

Conversation

@fperrad
Copy link
Contributor

@fperrad fperrad commented Oct 29, 2019

No description provided.

@minad
Copy link
Member

minad commented Oct 30, 2019

uL suffix is wrong for small digits (MP_16BIT).

@fperrad
Copy link
Contributor Author

fperrad commented Oct 31, 2019

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);
Copy link
Contributor

@czurnieden czurnieden Oct 31, 2019

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;

Copy link
Contributor Author

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

Copy link
Contributor

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().

Copy link
Contributor Author

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.

Copy link
Contributor

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 in rand_double().

No it wouldn't, because it is just a cast; we use the value not the bitpattern.
Sorry, my fault.

@sjaeckel sjaeckel merged commit b4c4257 into libtom:develop Nov 5, 2019
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.

4 participants