Skip to main content

Timeline for Credit card validation

Current License: CC BY-SA 3.0

11 events
when toggle format what by license comment
Apr 12, 2017 at 7:31 history edited CommunityBot
replaced http://programmers.stackexchange.com/ with https://softwareengineering.stackexchange.com/
Aug 16, 2015 at 15:27 comment added CodesInChaos 999 999 999 999 999 has 15 digits, but when I run it I get 16. Using (int)floor(log10(n)) + 1.
Aug 16, 2015 at 14:59 comment added CodesInChaos Even without floating point errors your code is wrong, ceil(log10(10)) == 1 and ceil(log10(9)) == 0. The "correct" formula would be (int)floot(Log10(n)) + 1
Aug 16, 2015 at 14:51 comment added CodesInChaos I'm not a fan on the log10 approach since you'd need to be sure that floating point rounding errors won't lead to an off-by-one error. AFAIK the IEEE guaranteed for transcendental functions are relatively weak and C's guarantees might be even weaker. In addition to that, 16 digits corresponds to 53.15 bits, so you won't even be able to represent some of them exactly as double.
Aug 16, 2015 at 10:59 comment added Caridorc @StefanRendevski :) thanks for knowing the rules
Aug 16, 2015 at 10:54 comment added Stefan Rendevski @Caridorc I meant I updated my file, not the code posted in this question. Sorry for the misunderstanding.
Aug 16, 2015 at 8:06 comment added Caridorc @StefanRendevski Never change code in question. Ask another question after implementing the improvments
Aug 16, 2015 at 0:18 comment added Stefan Rendevski Updated the code with some of your suggestions. The function sprintf wasn't covered in the lectures, so I'll leave that out for now. Since I cannot use functions, is the ceil(log10(credit_card)) more readable than my for loop when it comes to calculating the number of digits?
Aug 15, 2015 at 22:05 vote accept Stefan Rendevski
Aug 15, 2015 at 21:59 review First posts
Aug 15, 2015 at 22:03
Aug 15, 2015 at 21:57 history answered Obenland CC BY-SA 3.0