# Changeset d1ab5331 for src/libcfa/rational.c

Ignore:
Timestamp:
May 4, 2016, 2:24:23 PM (8 years ago)
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
Children:
99ee64d
Parents:
a1d6d80
Message:

add constructors to rational type

File:
1 edited

Unmodified
Added
Removed
• ## src/libcfa/rational.c

 ra1d6d80 // Created On       : Wed Apr  6 17:54:28 2016 // Last Modified By : Peter A. Buhr // Last Modified On : Thu Apr 21 07:33:03 2016 // Update Count     : 22 // Last Modified On : Wed May  4 14:16:14 2016 // Update Count     : 25 // // constructors Rational rational() { return (Rational){ 0, 1 }; void ?{}( Rational * r ) { r{ 0, 1 }; } // rational Rational rational( long int n ) { return (Rational){ n, 1 }; void ?{}( Rational * r, long int n ) { r{ n, 1 }; } // rational Rational rational( long int n, long int d ) { void ?{}( Rational * r, long int n, long int d ) { long int t = simplify( &n, &d );                                    // simplify return (Rational){ n / t, d / t }; r->numerator = n / t; r->denominator = d / t; } // rational Rational narrow( double f, long int md ) { if ( md <= 1 ) {                                                                        // maximum fractional digits too small? Rational t = rational( f, 1 );                                  // truncate fraction return t; return (Rational){ f, 1};                                               // truncate fraction } // if k[2] = x * k[1] + k[0]; k[0] = k[1]; k[1] = k[2]; } // for Rational t = rational( neg ? -h[1] : h[1], k[1] ); return t; return (Rational){ neg ? -h[1] : h[1], k[1] }; } // narrow
Note: See TracChangeset for help on using the changeset viewer.