Trying to set the angle variable


angle <- pi * (3 - sqrt(5)) = 2.14

im trying to set it to 2.0 , ive tried different combos of numbers



What is it you are trying to do?

Your prose description alone isn’t sufficient to understand the issue you are running into. You need to be more specific and you also need to make a simple reprex that:

  1. Builds the input data you are using.
  2. The function you are trying to write, even if it doesn’t work.
  3. Usage of the function you are trying to write, even if it doesn’t work.
  4. Builds the output data you want the function to produce.

You can learn more about reprex’s here:

Right now the is an issue with the version of reprex that is in CRAN so you should download it directly from github.

Until CRAN catches up with the latest version install reprex with


In any case I believe what you have there is a formula for the golden angle.

But the golden angle isn’t 2 radians, it is about 2.39996322972865332 radians.

    approx_golden_angle = 2.39996322972865332
    calc_golden_angle <- pi * (3 - sqrt(5)) 
#> [1] 2.399963
#> [1] 2.399963
    approx_golden_angle - calc_golden_angle
#> [1] 4.440892e-16

Created on 2018-03-10 by the reprex package (v0.2.0).

Down to 6 decimal places the calculation is a good approximation.

Keep in mind that floating point arithmetic is almost never accurate and is neither commutative nor associative. Here is an alternate, equivalent calculation that produces a different value for the golden angle.

    calc_golden_angle <- pi * (3 - sqrt(5)) 
    calc_golden_angle2 <- pi * 3 - pi * sqrt(5) 

    calc_golden_angle2 - calc_golden_angle
#> [1] -4.440892e-16

Created on 2018-03-10 by the reprex package (v0.2.0).


It’s still not clear what the issue is that you are having.

As is we can’t work with the code in this example without typing it all in and some of can’t even be seen.

Most everyone here is answering questions on their own time so it’s really appreciated if you do as much as you can to make as easy as possible for them to help you.

Please look at how to make a reprex and post the code in this example in a reprex along with some clarification as to what the issue is you are running into. It will be appreciated be everyone here who takes the time to see what the problem is.