Skip to main content
GraniteRobert's user avatar
GraniteRobert's user avatar
GraniteRobert's user avatar
GraniteRobert
  • Member for 10 years, 7 months
  • Last seen more than 3 years ago
awarded
awarded
awarded
awarded
awarded
revised
Loading…
awarded
comment
Prettify math formula in code
@200_success: A & S 26.2.17 explicitly says the valid inputs are non-negative. The code shouldn't be called with negative values, and in an environment where invalid calls are likely, maybe it should include a check. The error bound is listed as 7.5 * 10 ** -8. Is the accuracy specified somehow for math.erfc? I'm not suggesting either algorithm is better or worse, I'm just saying the tradeoffs should be understood in the context of the problem being solved.
comment
Prettify math formula in code
Use caution before changing to a different algorithm to do the "same" calculation. Of the 8 or so different approximations in Abramowitz and Stegun (A & S) for the normal distribution function, somebody picked this particular approximation. There might have been a very good reason for the choice. Don't assume an off-the-shelf library function will give adequate accuracy for the problem at hand, unless you take the time to understand the ugly details of the calculation. People who rummage around in A & S tend not to be casual users; accuracy and error bounds may be very important.
answered
Loading…
comment
Seeking improved Objective-C permutation algorithm
I echo nhgrif's question... if the array elements are single characters, this implementation is really overkill. You should use an NSMutableString, or just a C string, in that case. You could improve the question by adding sample code that calls your permute method.
revised
Revised Job Queue for Strategy Game
Manually fixed an auto-correct typo.
Loading…
comment
Output int from string input
strtok_r also modifies the input string. I don't have a suggested one-size-fits-all replacement to suggest; it depends on the situation. In this case, I might start with sscanf to find one integer at a time from the string.
answered
Loading…
comment
Calculating the circumference and area of a circle
I wondered if you intended separate lines in the output. I thought I was misunderstanding my JAVA.
comment
Calculating the circumference and area of a circle
1. Could you attach some sample output? 2. Why restrict the radius to int? The class name, Circle, suggests something more general.
comment
Adding friends to address book app
@nhgrif: Why is a forin loop generally faster than a regular for loop traversing the whole array?
answered
Loading…
awarded
comment
Fraction (rational number) structure with custom operators
I would explore having your init function return an optional Fraction, with a nil value when the denominator is 0. Fraction(numerator:1, denominator:0) should NOT just silently return a Fraction object that is invalid and will cause trouble later. Swift's optionals seem tailor-made to handle this situation.