Reputation: 483
I've seen some code online and I'm trying to work out what it is doing. In particular, I've never seen "1e" convention before.
time_t currentTime;
time(¤tTime);
uint64_t currentTime = (uint64_t)currentTime * 1e6;
Upvotes: 8
Views: 46306
Reputation: 1371
I've seen some code online and I'm trying to work out what it is doing. In particular, I've never seen "1e" convention before.
As others have mentioned, practically speaking, 1e6
is scientific notation for 10^6 which is 1000000 or better known as 1 million. But as has already been mentioned, by David, this is actually treated as a double
in C and the value is actually 1000000.0
.
But I feel like these answers only focus on that specific piece of the code you provided and not the whole so I wanted to provide some additional context for you since you are trying to work out what the code is doing.
For these lines:
time_t currentTime;
time(¤tTime);
time
takes a pointer time_t
and operates on it, presumably writing some semblance of time to it.
The next line is actually illegal because currentTime
was already declared so let's make a small modification:
uint64_t convertedTime = (uint64_t)currentTime * 1e6;
This line converts time_t currentTime
to an unsigned 64-bit integer then multiplies it by 1e6
or 1000000.0
. This is likely being done for unit conversion. For instance, let's assume time
wrote the time in microseconds (1e-6
, 10^-6, or .000001
) to currentTime
so multiplying it by 1e6
will give you seconds. And I say that just because of what appears to be a unit conversion here not because I actually know what time
did (i.e. I'm taking the code at face value here).
Upvotes: 9
Reputation: 484
That is 1e6, not le6, and it means 1 * 10^6 or 1000000.0
It is scientific notation.
Upvotes: 15
Reputation: 87376
In C, 1e6
has type double
and its value is 1 times 10 raised to the 6th power. It is equivalent to 1000000.0
.
Do not get fooled by the other answers: 1e6
does not mean the same thing as 1000000
in C, because 1e6
has type double
while 1000000
will have some integer type. There are big differences in behavior between floating-point types like double
and integers types.
The syntax for writing numbers like 1e6
is defined in the "Floating constants" section of the C11 specification (and earlier versions too). It's kind of like scientific notation.
Upvotes: 6
Reputation: 3866
It's 1e6
Scientific notation for Math.pow(10, 6) == 1000000
/* yes, you can do that with pretty much any standard programming language, including C */
Upvotes: 1