Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing small (1.0E-12) numbers as doubles in scientific notation

Here's the setup:

For my Bachelor's thesis, I want to test jet algorithms used at the LHC. Basically the first step is the folowing: Given some 4-momentum

p[0] = nullvector(45.0000000000106,33.03951484238976,14.97124733712793,26.6317895033428)

I want to simulate experimental data by adding some (like, 50) randomly generated 4-vectors to the last three components in the order of 10^(-12), so that they are small (that's where the interesting physics happens), but significantly above the double float precision of 15 decimals. So the quick-and-dirty solution to that is the following:

seed=time(NULL);
srand(seed);
random=(rand()%9001)*1.0E-15;
random=random+1E-12;
printf("%.15E\n",random);

This gives me random numbers between 1E-12 and 10E-12 (=1E-11) with three decimals max, so that in "real" doubles, that gives me 15 decimals.

Now to the point: Can I store numbers in that order with more than three decimals without overstepping double float precision?

PS: Is there a better way to generate small random numbers? (This sounds like another topic ;))

like image 258
Wojciech Morawiec Avatar asked Nov 13 '22 10:11

Wojciech Morawiec


1 Answers

The traditional method for creating floating point random numbers is to make it a range [0-1) by taking double x = (double)rand()/RAND_MAX; - then multiply by 9001E-1 to scale your range to the 1E-12 to 1E-15 values [zero inclusive].

like image 55
Mats Petersson Avatar answered Nov 15 '22 08:11

Mats Petersson