Ignore:
Timestamp:
May 4, 2016, 2:24:23 PM (8 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, with_gc
Children:
99ee64d
Parents:
a1d6d80
Message:

add constructors to rational type

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/rational.c

    ra1d6d80 rd1ab5331  
    1111// Created On       : Mon Mar 28 08:43:12 2016
    1212// Last Modified By : Peter A. Buhr
    13 // Last Modified On : Fri Apr  8 11:27:48 2016
    14 // Update Count     : 21
     13// Last Modified On : Wed May  4 14:19:36 2016
     14// Update Count     : 24
    1515//
    1616
     
    2020
    2121int main() {
    22         Rational a, b, c;
    2322        sout | "constructor" | endl;
    24         a = rational( 3 );
    25         b = rational( 4 );
    26         c = rational();
     23        Rational a = { 3 }, b = { 4 }, c;
    2724        sout | a | b | c | endl;
    28         a = rational( 4, 8 );
    29         b = rational( 5, 7 );
     25        a = (Rational){ 4, 8 };
     26        b = (Rational){ 5, 7 };
    3027        sout | a | b | endl;
    31         a = rational( -2, -3 );
    32         b = rational( 3, -2 );
     28        a = (Rational){ -2, -3 };
     29        b = (Rational){ 3, -2 };
    3330        sout | a | b | endl;
    34         a = rational( -2, 3 );
    35         b = rational( 3, 2 );
     31        a = (Rational){ -2, 3 };
     32        b = (Rational){ 3, 2 };
    3633        sout | a | b | endl;
    3734
    3835        sout | "logical" | endl;
    39         a = rational( -2 );
    40         b = rational( -3, 2 );
     36        a = (Rational){ -2 };
     37        b = (Rational){ -3, 2 };
    4138        sout | a | b | endl;
    4239        sout | a == 1 | endl;
     
    5552
    5653        sout | "conversion" | endl;
    57         a = rational( 3, 4 );
     54        a = (Rational){ 3, 4 };
    5855        sout | widen( a ) | endl;
    59         a = rational( 1, 7 );
     56        a = (Rational){ 1, 7 };
    6057        sout | widen( a ) | endl;
    61         a = rational( 355, 113 );
     58        a = (Rational){ 355, 113 };
    6259        sout | widen( a ) | endl;
    6360        sout | narrow( 0.75, 4 ) | endl;
     
    6562        sout | narrow( 3.14159265358979, 256 ) | endl;
    6663
    67         Rational x, y;
    68         x = rational( 1, 2 );
    69         y = rational( 2 );
     64        Rational x = { 1, 2 }, y = { 2 };
    7065        sout | x - y | endl;
    7166        sout | x > y | endl;
     
    7368        sout | y | denominator( y, -2 ) | y | endl;
    7469
    75         Rational z;
    76         z = rational( 0, 5 );
     70        Rational z = { 0, 5 };
    7771        sout | z | endl;
    7872
    7973        sout | x | numerator( x, 0 ) | x | endl;
    8074
    81         x = rational( 1, MAX ) + rational( 1, MAX );
     75        x = (Rational){ 1, MAX } + (Rational){ 1, MAX };
    8276        sout | x | endl;
    83         x = rational( 3, MAX ) + rational( 2, MAX );
     77        x = (Rational){ 3, MAX } + (Rational){ 2, MAX };
    8478        sout | x | endl;
    8579
Note: See TracChangeset for help on using the changeset viewer.