Ignore:
Timestamp:
Apr 8, 2016, 5:22:29 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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, string, with_gc
Children:
3da470c
Parents:
3d9b5da
Message:

C99 compound literals now work, comment rational code, clean up hoisting AddVisit?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/rational

    r3d9b5da r630a82a  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // rational --
     7// rational -- Rational numbers are numbers written as a ratio, i.e., as a fraction, where the numerator (top number)
     8//     and the denominator (bottom number) are whole numbers. When creating and computing with rational numbers, results
     9//     are constantly reduced to keep the numerator and denominator as small as possible.
    810//
    911// Author           : Peter A. Buhr
    1012// Created On       : Wed Apr  6 17:56:25 2016
    1113// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Apr  7 17:23:36 2016
    13 // Update Count     : 9
     14// Last Modified On : Fri Apr  8 11:38:27 2016
     15// Update Count     : 15
    1416//
    1517
    1618#include "iostream"
    1719
     20// implementation
    1821struct Rational {
    1922        long int numerator, denominator;                                        // invariant: denominator > 0
    2023}; // Rational
    2124
     25// constants
    2226extern struct Rational 0;
    2327extern struct Rational 1;
    2428
    25 long int gcd( long int a, long int b );
    26 long int simplify( long int *n, long int *d );
    27 Rational rational();                                                                    // constructor
    28 Rational rational( long int n );                                                // constructor
    29 Rational rational( long int n, long int d );                    // constructor
     29// constructors
     30Rational rational();
     31Rational rational( long int n );
     32Rational rational( long int n, long int d );
     33
     34// getter/setter for numerator/denominator
    3035long int numerator( Rational r );
    3136long int numerator( Rational r, long int n );
     37long int denominator( Rational r );
    3238long int denominator( Rational r, long int d );
     39
     40// comparison
    3341int ?==?( Rational l, Rational r );
    3442int ?!=?( Rational l, Rational r );
     
    3745int ?>?( Rational l, Rational r );
    3846int ?>=?( Rational l, Rational r );
     47
     48// arithmetic
    3949Rational -?( Rational r );
    4050Rational ?+?( Rational l, Rational r );
     
    4252Rational ?*?( Rational l, Rational r );
    4353Rational ?/?( Rational l, Rational r );
     54
     55// conversion
    4456double widen( Rational r );
    4557Rational narrow( double f, long int md );
     58
     59// I/O
    4660forall( dtype istype | istream( istype ) ) istype * ?|?( istype *, Rational * );
    4761forall( dtype ostype | ostream( ostype ) ) ostype * ?|?( ostype *, Rational );
Note: See TracChangeset for help on using the changeset viewer.