0

need to enum all points on a line between two points defined by coords p1(x1,y1) p2(x2,y2) which count of digit numbers are equal to predefined number:

e.g. take a points with two digits only

(1.234456, 2.345567) - not meets a requirement
(2.34, 5.4) - meets a requirement

(3.45,6.67567567567) - not meets the requirement

this looks clear in terms of arithmetic. 1. find a function for that line like y = A*x + B 2. go throu all X numbers between first and second points with a step of 0.01 and check that Y is also having two digits.

but the problem is in understanding e.g. number : 5.54999999 - doesn't really accept my requirement or just wrong representation of 5.55?

any idea how to solve the problem?

amigo421
  • 2,429
  • 4
  • 26
  • 55
  • 2
    See [What every computer scientist should know about floating point](http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html). – Thomas Matthews Apr 04 '16 at 13:43
  • http://www.exploringbinary.com/why-0-point-1-does-not-exist-in-floating-point/ – Raph Schim Apr 04 '16 at 14:08
  • A first step to your algorithm should be: Convert the numbers to integers, multiplying by some power of 10. After that step, rounding will not be an issue anymore. – Sjoerd Apr 04 '16 at 14:14
  • it doesn't completely solve the problem on the first step , even with increasing the data to long numbers, A and B numbers in equation will rational numbers and will not valid e.g. in my sample A = 0.7 (should be) but 0.699999 after calculation this – amigo421 Apr 04 '16 at 14:46

0 Answers0