0

I have values of the magnitude of e-11 (representing light) and I would like to bring them into [nm]. I figured out that, e.g.

df$w.length[1]
[1] 1.239842e-11

df$w.length[1] + 1e-11
[1] 2.239842e-11

works but

> df$w.length[1] + 1e9
[1] 1e+09

doesn't. Also simply

> 1e-12 + 1e9
[1] 1e+09

not as well. Why is that?

Ben
  • 1,432
  • 4
  • 20
  • 43
  • 1
    [R FAQ 7.31](https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f) and [Why are these numbers not equal?](https://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal) and [Controlling the number of digits in print output](https://stackoverflow.com/questions/2287616/controlling-number-of-decimal-digits-in-print-output-in-r) – Rui Barradas Nov 10 '22 at 11:14
  • `1e-12` is a vanishingly small number. `1e+09` is an enormous number. Adding them together basically gives you `1e+09` plus some noise. It's ~ `1,000,000,000.0000000000001`. Which gets displayed as 1e9 due to rounding. – Paul Stafford Allen Nov 10 '22 at 11:15
  • 1
    It's also falling foul of floating point issues as displayed in @RuiBarradas link - you can demonstrate this by doing `1e+09 == (1e+09 + 1e-12)` which evaluates as `TRUE`. A more useful question would be this - you are converting from one unit to another - what it the first unit? – Paul Stafford Allen Nov 10 '22 at 11:18
  • Well, thanks, I'm trying to get a hold of this.. @PaulStaffordAllen I simply want to express e-11 in e^-9. The latter would be nanometers while the first would be 10-something in picometers. The unit is meters (for the wavelength). – Ben Nov 10 '22 at 11:28
  • But then there's an error in your question, `1.239842e-11 + 1e-9` is not the same as `1e-9`. In the question you have a difference in orders of magnitude of 20. – Rui Barradas Nov 10 '22 at 11:48
  • But isn't 1e-12 +1e9 = 1e-3? Hope that's not too dumb.. ah, wait, that's for division... well, true. How do I express 1e-11 in nm then? – Ben Nov 10 '22 at 11:50
  • 1e-12 * 1e-9 = 1e-3. Multiplying the numbers can be shown by adding or subtracting the exponents. Adding or subtracting the entire number is not the same. – Paul Stafford Allen Nov 10 '22 at 11:54
  • Yeah, sorry,.. it's a while that I used to do this.. I guess I simply have to mulitply by 100 to express numbers of 1e-11 in terms of 1e-9, right? – Ben Nov 10 '22 at 11:56

0 Answers0