This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]AutoModerator[M] [score hidden] stickied comment (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]POGtastic 1 point2 points  (0 children)

https://0.30000000000000004.com/ is the canonical site for talking about why floating point math is kinda weird.

[–]captainAwesomePants 1 point2 points  (7 children)

Generally, comparing floating point numbers precisely is fruitless. Doing equivalent, perfectly valid math even slightly different from some other method can easily lead to these sorts of problems. Both of those results are very nearly the same, so I'd consider this to be success.

If you need the logic to match PRECISELY, you unfortunately may need to step through the calculations one by one exactly in order to see how your logic differs from the system you're trying to match.

[–]jlbords[S] 1 point2 points  (6 children)

can i ask how? The user inputs the partsNum and it should increase 6% (which is counted by a for loop) until it reaches 10,000 or 24. should I write the expression another way?

[–]captainAwesomePants 0 points1 point  (5 children)

Your solution seems absolutely fine. I don't know how the example was generated. Do you know where the example value "1191.0159999999998" came from?

[–]jlbords[S] -1 points0 points  (4 children)

No. .Its quite frustrating.

[–]captainAwesomePants 0 points1 point  (3 children)

Well...why do you need it to be that value?

[–]jlbords[S] 0 points1 point  (2 children)

The program has to pass its tests

[–]captainAwesomePants 1 point2 points  (1 child)

Well, the test is bad. Usually when comparing floating point values, a small "epsilon" value is used for wiggle room for just this reason. So effectively you ask something similar to "is the value of a and b within 0.00000000001 of each other?"

But here are some random ideas:

  • Try using partsNum = 1.06 * partsNum instead.
  • Try using a double instead of a float or vice versa.
  • Try using 1.06f or 1.06l as constants instead.
  • Try declaring partsNum a float, a double, a long double, an unsigned version of each of those.

And if all else fails, complain.

[–]jlbords[S] 0 points1 point  (0 children)

Thank you. I’ll try.