Perry Graham wrote:I guess my answer would have to be something that addresses the x1 = increment part of the forloop, but I'm not exactly sure how to tackle that.
Campbell Ritchie wrote:Welcome to the Ranch
Don't use Math#pow(x, 2) for squares when you will usually get faster performance with x * x.
"privilege" comes from the Latin words for "private" and "law" (legal) and dates to feudal times. To "claim privilege" meant that you were above the laws that applied to the common people.
I hate signatures!
We used to use 60×4=240 as a base.Tim Holloway wrote:. . . . The Babylonians knew what they were doing using 60 for a base. . . ..
Campbell Ritchie wrote:Use integer arithmetic for the loop header.
That looks horribly complicated. There has to be a more straightforward way to do that, and things straightforward are less likely to go wrong. What about 1 + (int)(radius / increment * 2)?Perry Graham wrote: . . .
. . . . This got me:Campbell Ritchie wrote:Use integer arithmetic for the loop header.
You are not calculating 0.00. You are calculating something small and negative, and then rounding it to two dp with %9.2f. It must be the 1.3877787807814457E16. If you look in the documentation for BigDecimal, you will find that the nearest double representation of 0.1 is very slightly too large, but it you add it to itself 10× the rounding error goes the other way and you end up with 0.9999999999... That is how the loop I showed you yesterday runs 11×. . . . not the 0.00 problem
That looks unnecessarily complicated again. You should be able to calculate values for the loop variant such that you can use i * 0.01. That will introduce rounding errors, but at least the errors won't be cumulative, and when you multiply by 0 you will actually get 0.0.in the loop I subtracted the increment value from it, then multiplied it by 100.0. From there I used the Math.round to get it to a nice usable value, then divided by 100.0 to get back to the desired decimal place.
It would be better to calculate the likely values of the loop variant on paper first. Work out a formula, and you can be confident it will be correct. As it is, if there are any rounding errors, you can be pretty confident that your if will miss the equality you are looking for.I also added an ifstatement at the beginning of the forloop just in case my loopInt was off by a couple of values . . .
I hate signatures!
That looks horribly complicated. There has to be a more straightforward way to do that, and things straightforward are less likely to go wrong. What about 1 + (int)(radius / increment * 2)?
No more fooling around. Read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn KlassenKoop
https://coderanch.com/wiki/718759/books/BuildingWorldBackyardPaulWheaton
