(12C) Decimal to Fraction
|
08-09-2018, 12:16 PM
Post: #35
|
|||
|
|||
RE: (12C) Decimal to Fraction
(08-09-2018 09:27 AM)Dieter Wrote: I think that q can also be calculated via q = c – (c-u) mod v. Can you confirm this? q = u + (c-u)//v * v = c - ((c-u) - (c-u)//v * v) = c - (c-u) mod v -- confirmed Quote:I do not quite understand why earlier code (and Joe's as well) used the CEIL function why here it's the FLOOR (or INT) function. Thomas code use ceiling because v were over-shoot passed c: q = v - k u <= c k u >= v - c k >= (v - c) / u k = ceiling((v-c) / u) -- to maximize q My patch, both u, v are below c: q = u + k v <= c k <= (c - u) / v k = (c - u) // v -- to maximize q Quote:Thomas even used 1+INT() which in most cases is the same as CEIL... but not for integer arguments. 1+INT() for ceiling is wrong A simple example is 0.00005, u, v = 1, 20000 Since u = 1, 1+INT() always over-shoot ceiling by 1 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)