¡@

Home 

2014/10/15 ¤U¤È 10:03:31

iphone Programming Glossary: ai

Convert decimal to fraction in Objective-C?

http://stackoverflow.com/questions/5552537/convert-decimal-to-fraction-in-objective-c

share improve this question Objective C uses pure C for basically all primitive mathematical operations. This being said you'll find all necessary information along with C code in the answers of this other question How to convert floats to.. to human readable fractions Specifically this answer featuring actual C code . Here is a quick c function wrapper of said algorithm typedef struct long nominator long denominator double error Fraction Find rational approximation to given real.. fractionFromReal double realNumber long maxDenominator double atof int atoi void exit long m 2 2 double startx long ai startx realNumber initialize matrix m 0 0 m 1 1 1 m 0 1 m 1 0 0 loop finding terms until denom gets too big while m 1 0..