I have a code writes a robot coordination in a file. Sometimes, for an unknown reason, instead of a number like 0.01845, it writes 6.92113e-310. So I'd like to filter data raised to a power greater than -12. Is there a way to achieve this in C++?
Asked
Active
Viewed 81 times
-1
-
3Yes, it's possible. If it's a number, you can compare with `1e-12`, e.g. `auto num = 6.92113e-310; if (num < 1e-12) ...` – jabaa Oct 25 '22 at 09:02
-
1-310 is less than 12. It's even less than zero. `6.92113e-310.` is 0.0000(....)00069, there are 310 zeroes before the 6. – MSalters Oct 25 '22 at 14:13
-
Round the output to a certain number of digits behind the decimal point. How do you output the data? cout? printf? fmt? – Sebastian Oct 25 '22 at 17:44
-
@MSalters, sorry I made a mistake in question. It's not 12, but -12. – Edvard Oct 26 '22 at 06:55
-
@Sebastian, I write data as myfile << parsed_data[0] << ";"; – Edvard Oct 26 '22 at 06:57
-
@Edvard: Doesn't really change my point. -310 is also less than -12. – MSalters Oct 26 '22 at 09:42
1 Answers
-1
Just to help with the math: you get the exponent using std::log10
.
This actually returns the exponent as the integer part, and the significand (the 6.9113 before the e) controls the fractional part of log10
.
Filtering a collection by a predicate should be in your C++ textbook.

MSalters
- 173,980
- 10
- 155
- 350