Post Reply 
(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
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(12C) Decimal to Fraction - Gamo - 08-06-2018, 12:33 PM
RE: (12C) Decimal to Fraction - Dieter - 08-06-2018, 08:44 PM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 07:29 AM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 01:02 PM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 11:38 AM
RE: (12C) Decimal to Fraction - Gamo - 08-07-2018, 09:29 AM
RE: (12C) Decimal to Fraction - Joe Horn - 08-07-2018, 06:28 PM
RE: (12C) Decimal to Fraction - Dieter - 08-07-2018, 07:10 PM
RE: (12C) Decimal to Fraction - Joe Horn - 08-08-2018, 12:28 AM
RE: (12C) Decimal to Fraction - Dieter - 08-08-2018, 07:04 PM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 09:27 AM
RE: (12C) Decimal to Fraction - Albert Chan - 08-09-2018 12:16 PM
RE: (12C) Decimal to Fraction - Dieter - 08-08-2018, 09:44 PM
RE: (12C) Decimal to Fraction - Gamo - 08-09-2018, 12:51 AM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 07:46 AM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 08:09 AM
RE: (12C) Decimal to Fraction - Gamo - 08-09-2018, 09:16 AM
RE: (12C) Decimal to Fraction - Dieter - 08-09-2018, 10:30 AM
RE: (12C) Decimal to Fraction - Dieter - 08-10-2018, 12:28 PM
RE: (12C) Decimal to Fraction - Gamo - 05-07-2019, 01:44 AM
RE: (12C) Decimal to Fraction - Dieter - 08-10-2018, 07:06 PM



User(s) browsing this thread: 1 Guest(s)