Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/examples/square.c

    r86bd7c1f rb63e376  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed May 27 18:43:34 2015
    13 // Update Count     : 2
     12// Last Modified On : Tue Mar  8 22:05:48 2016
     13// Update Count     : 27
    1414//
    1515
    16 extern "C" {
    17 #include <stdio.h>
    18 }
     16#include <fstream>
    1917
    20 forall( type T | { T ?*?( T, T ); } )
     18forall( otype T | { T ?*?( T, T ); } )
    2119T square( T t ) {
    2220        return t * t;
    23 }
    24 
    25 //char ?*?( char a1, char a2 ) {
    26 //      return (char)( (int)a1 * (int)a2 );
    27 //}
     21} // square
    2822
    2923int main() {
    30         char c = 5;
    31         short int s = 5;
    32         int i = 5;
    33         float f = 5.0;
    34         double d = 5.0;
    35 //      printf( "result of square of 5 is %d\n", (char)square( c ) );
    36         printf( "result of square of 5 is %d\n", square( s ) );
    37         printf( "result of square of 5 is %d\n", square( i ) );
    38         printf( "result of square of 5 is %f\n", square( f ) );
    39         printf( "result of square of 5 is %f\n", square( d ) );
    40 }
     24#if 0
     25        sout | "result of squaring 9 is " | endl;
     26
     27        // char does not have multiplication.
     28        char ?*?( char a1, char a2 ) {
     29                return (char)((int)a1 * (int)a2);
     30        } // ?*?
     31        char c = 9;
     32        sout | "char\t\t\t" | square( c ) | endl;
     33
     34        sout | square( s ) | endl;
     35#endif
     36        short s = 9;
     37        square( s );
     38#if 0
     39        signed int i = 9;
     40        sout | "signed int\t\t" | square( i ) | endl;
     41
     42        unsigned int ui = 9;
     43        sout | "unsigned int\t\t" | square( ui ) | endl;
     44
     45        long int li = 9;
     46        sout | "signed long int\t\t" | square( li ) | endl;
     47
     48        unsigned long int uli = 9;
     49        sout | "unsigned long int\t" | square( uli ) | endl;
     50
     51        signed long long int lli = 9;
     52        sout | "signed long long int\t" | square( lli ) | endl;
     53
     54        unsigned long long int ulli = 9;
     55        sout | "unsigned long long int\t" | square( ulli ) | endl;
     56
     57        float f = 9.0;
     58        sout | "float\t\t\t" | square( f ) | endl;
     59
     60        double d = 9.0;
     61        sout | "double\t\t\t" | square( d ) | endl;
     62
     63        long double ld = 9.0;
     64        sout | "long double\t\t" | square( ld ) | endl;
     65#endif
     66} // main
    4167
    4268// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.