/************************************************************************/
/*                                                                      */
/*         Code generated by FED-CASE V1.2  Code Generator              */
/*                  © Joosen Software Development                       */
/*                  All rights reserved 1993-1995                       */
/*                                                                      */
/************************************************************************/


/************************************************************************/
/*                                                                      */
/*                          Start of Includes                           */
/*                                                                      */
/************************************************************************/

#include <math.h>
#include <stdio.h>

/************************************************************************/
/*                                                                      */
/*                           End of Includes                            */
/*                                                                      */
/************************************************************************/

/************************************************************************/
/*                                                                      */
/*                    Start of source prototype file                    */
/*                                                                      */
/************************************************************************/

#include <proto/proto_math.h>

/************************************************************************/
/*                                                                      */
/*                     End of source prototype file                     */
/*                                                                      */
/************************************************************************/


/************************************************************************/
/* Procedure  : double D_OwnPow(FD_alpha,FI_exponent)                   */
/* Function   :                                                         */
/* Designer   : C.Joosen & R.Heijmans                                   */
/* Date       : Fri Mar 10 21:11:26 1995                                */
/*                                                                      */
/* Modificat  :                                                         */
/* Handler    :                                                         */
/* Modific.   :                                                         */
/*                                                                      */
/************************************************************************/

double D_OwnPow(double FD_alpha, int FI_exponent)
{
double LD_beta;

    LD_beta = 1.0;
    while( FI_exponent )
    {
        LD_beta *= FD_alpha ;
        FI_exponent -- ;
    }                                                      /* end of while(FI_exponent) */
return ( LD_beta );
}                                                          /* end of D_OwnPow */

/************************************************************************/
/* Procedure  : double D_OwnSine(FD_alpha)                              */
/* Function   :                                                         */
/* Designer   : C.Joosen & R.Heijmans                                   */
/* Date       : Fri Mar 10 21:11:27 1995                                */
/*                                                                      */
/* Modificat  :                                                         */
/* Handler    :                                                         */
/* Modific.   :                                                         */
/*                                                                      */
/************************************************************************/

double D_OwnSine(double FD_alpha)
{
double LD_beta;

    LD_beta = FD_alpha - ( D_OwnPow( FD_alpha, 3 ) / I_OwnFact( 3 ) );
    LD_beta = LD_beta + ( D_OwnPow( FD_alpha, 5 ) / I_OwnFact( 5 ) );
return ( LD_beta );
}                                                          /* end of D_OwnSine */

/************************************************************************/
/* Procedure  : double D_OwnCosine(FD_alpha)                            */
/* Function   :                                                         */
/* Designer   : C.Joosen & R.Heijmans                                   */
/* Date       : Fri Mar 10 21:11:27 1995                                */
/*                                                                      */
/* Modificat  :                                                         */
/* Handler    :                                                         */
/* Modific.   :                                                         */
/*                                                                      */
/************************************************************************/

double D_OwnCosine(double FD_alpha)
{
double LD_beta;

    LD_beta = 1 - ( D_OwnPow( FD_alpha, 2 ) / I_OwnFact( 2 ) );
    LD_beta = LD_beta + ( D_OwnPow( FD_alpha, 4 ) / I_OwnFact( 4 ) );
return ( LD_beta );
}                                                          /* end of D_OwnCosine */

/************************************************************************/
/* Procedure  : double D_OwnAbs(FD_value)                               */
/* Function   :                                                         */
/* Designer   : C.Joosen & R.Heijmans                                   */
/* Date       : Fri Mar 10 21:11:27 1995                                */
/*                                                                      */
/* Modificat  :                                                         */
/* Handler    :                                                         */
/* Modific.   :                                                         */
/*                                                                      */
/************************************************************************/

double D_OwnAbs(double FD_value)
{

    if ( FD_value < 0.0 )
    {
        FD_value = - FD_value;
    }                                                      /* end of 'if(FD_value < 0.0)' */
return ( FD_value );
}                                                          /* end of D_OwnAbs */

/************************************************************************/
/* Procedure  : double D_OwnSquareRoot(FD_root,FD_prec)                 */
/* Function   :                                                         */
/* Designer   : C.Joosen & R.Heijmans                                   */
/* Date       : Fri Mar 10 21:11:27 1995                                */
/*                                                                      */
/* Modificat  :                                                         */
/* Handler    :                                                         */
/* Modific.   :                                                         */
/*                                                                      */
/************************************************************************/

double D_OwnSquareRoot(double FD_root, double FD_prec)
{
double LD_Diff;
double LD_diff;
double LD_x2;
double LD_x1;

    LD_x1 = 1.0;
    LD_x2 = 0.5 * ( LD_x1 + FD_root / LD_x1 ) ;
    LD_diff = LD_x2 - LD_x1;
    LD_diff = D_OwnAbs( LD_Diff );
    while( LD_diff > FD_prec )
    {
        LD_x1 = LD_x2;
        LD_x2 = 0.5 * ( LD_x1 + FD_root / LD_x1 ) ;
        LD_diff = LD_x2 - LD_x1;
        LD_diff = D_OwnAbs( LD_Diff );
    }                                                      /* end of while(LD_diff > FD_prec) */
return ( LD_x2 );
}                                                          /* end of D_OwnSquareRoot */

/************************************************************************/
/* Procedure  : int I_OwnFact(FI_index)                                 */
/* Function   :                                                         */
/* Designer   : C.Joosen & R.Heijmans                                   */
/* Date       : Fri Mar 10 21:11:27 1995                                */
/*                                                                      */
/* Modificat  :                                                         */
/* Handler    :                                                         */
/* Modific.   :                                                         */
/*                                                                      */
/************************************************************************/

int I_OwnFact(int FI_index)
{
int LI_fact;

    if ( FI_index )
    {
        LI_fact = FI_index * I_OwnFact( FI_index - 1 );
    }
    else                                                   /* if(FI_index) */
    {
        LI_fact = 1;
    }                                                      /* end of else 'if(FI_index)' */
return ( LI_fact );
}                                                          /* end of I_OwnFact */

/************************************************************************/
/* Procedure  : void main()                                             */
/* Function   :                                                         */
/* Designer   : C.Joosen & R.Heijmans                                   */
/* Date       : Fri Mar 10 21:11:28 1995                                */
/*                                                                      */
/* Modificat  :                                                         */
/* Handler    :                                                         */
/* Modific.   :                                                         */
/*                                                                      */
/************************************************************************/

void main()
{
double LD_radangle;

    LD_radangle = ( 30 / 180 ) * 3.141592654;
    printf( "faculty of 7 == %d \n", I_OwnFact( 7 ) ) ;    /* printf:  */
    printf( "0.5 to the power of 5 == %.16f \n", D_OwnPow( (double)0.5, 5 ) );  /* printf:  */
    printf( "absolute value of -3.125E-6 == %.16f\n", D_OwnAbs( - 3.125E-6 ) ) ;  /* printf:  */
    printf( "System sine of %.16f is %.16f\n", LD_radangle, sin( LD_radangle ) ) ;  /* printf:  */
                                                           /* sin:  */
    printf( "Own sine    of %.16f is %.16f\n", LD_radangle, D_OwnSine( LD_radangle ) ) ;  /* printf:  */
    printf( "System sine of %.16f is %.16f\n", LD_radangle, sin( LD_radangle ) ) ;  /* printf:  */
                                                           /* sin:  */
    printf( "Own sine    of %.16f is %.16f\n", LD_radangle, D_OwnSine( LD_radangle ) ) ;  /* printf:  */
    printf( "System square root of %.16f is %.16f\n", 2.0, sqrt( (double)2.0 ) ) ;  /* printf:  */
                                                           /* sqrt:  */
    printf( "Own square root    of %.16f is %.16f\n", 2.0, D_OwnSquareRoot( (double)2.0, 1.0e-5 ) ) ;  /* printf:  */
    printf( "System square root of %.16f is %.16f\n", 5.0, sqrt( (double)5.0 ) ) ;  /* printf:  */
                                                           /* sqrt:  */
    printf( "Own square root    of %.16f is %.16f\n", 5.0, D_OwnSquareRoot( (double)5.0, 1.0e-5 ) ) ;  /* printf:  */
    printf( "System square root of %.16f is %.16f\n", 9999.0, sqrt( (double)9999.0 ) ) ;  /* printf:  */
                                                           /* sqrt:  */
    printf( "Own square root    of %.16f is %.16f\n", 9999.0, D_OwnSquareRoot( (double)9999.0, 1.0e-2 ) ) ;  /* printf:  */
}                                                          /* end of V_main */
