4 ms·
Ask HN: How do you pick numerical constants while programming?
Do you have a set of rules for doing this when the precise value of a number constant doesn't matter?
For example, would you use 0.875 or 0.9 in your code?
- deleted 3y ago[deleted]
- mikequinlan 3y agoWhat are you using the number for?
- amichail 3y agoSuppose it's not something that the user would see as a number. In that case, would you prefer 0.875 = 7/8 or 0.9? If both would work well, which would you put in the source?
- mikequinlan 3y agoI still need to understand the context. The last time I remember using a constant where it "didn't matter" what the exact number was, was maybe 30 years ago when we were manually allocating memory and had to decide to limit an array to an "even" number like 250 entries or to use the maximum that would fit (like 319 or something) and risk having to reduce it in later releases, possibly causing compatibility errors.
- dave4420 3y agoHow do you pick a number if someone asks you to pick a number, any number?
- ksaj 3y agoAccording to mentalists it'll always be 3 or 7, which is why they say "But don't pick 3, 'cos everybody picks 3" to force the number 7.
- ksaj 3y agoIt depends on tolerance. In electronics you allow for tolerance (+/- 5%). In carpentry you allow for tolerance (+/- 5mm). In cooking we allow for a huge tolerance (a pinch of salt! To Taste!) In delis, we allow for tolerance (ask for 100g of sliced ham, get more like 105g of sliced ham). But when creating a small circle on a computer screen, we suddenly use a dozen decimal places where one or two (and sometimes no decimal place) would do.