EvalhfDataProc - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


EvalhfDataProc

evaluate a procedure using the hardware floats evaluator with floats, procedures and rtables as arguments

 

Calling Sequence

Parameters

Description

Examples

Calling Sequence

EvalhfDataProc(kv, fn, n, args)

Parameters

kv

-

kernel handle of type MKernelVector

fn

-

Maple FUNCTION object

n

-

number of arguments

args

-

array of n hfdata structs

Description

• 

These functions can be used in external code with OpenMaple or define_external.

• 

EvalhfDataProc evaluates the function, f(args), to a numerical value using evalhf.  The n arguments provided are all hfdata structures representing complex floating point values, Maple procedures or rtables of type float[8].  The first argument must be inserted at args[1].  For example, to call f(3.14,2.718), set args[1] = 3.14, and args[2] = 2.718.  The value at args[0] is not used.

• 

The MapleTohfData function can be used to initialize the hfdata from a Maple procedure or rtable.  The DoubleTohfData and ComplexTohfData routines can be used to initialize an hfdata variable from doubles or pairs of doubles.

• 

The return value of EvalhfDataProc is an hfdata object.  Currently this will always represent a real double.  The real component of an hfData structure can be accessed using the RealhfData function.

Examples

    #include <math.h>

    #include "maplec.h"

    ALGEB MyNewtonData( MKernelVector kv, ALGEB *args )

    {

    M_INT i;

    FLOAT64 tolerance, newguess, res;

    hfdata guess[2];

    ALGEB f, fprime, x;

    if( 3 != MapleNumArgs(kv,(ALGEB)args) ) {

        MapleRaiseError(kv,"three arguments expected");

        return( NULL );

    }

    if( IsMapleProcedure(kv,args[1]) ) {

        f = args[1];

    }

    else {

        ALGEB indets;

        indets = EvalMapleProc(kv,ToMapleName(kv,"indets",TRUE),1,args[1]);

        if( !IsMapleSet(kv,indets) || MapleNumArgs(kv,indets) != 1 ) {

        MapleRaiseError(kv,"unable to find roots");

        return( NULL );

        }

        i = 1;

        f = EvalMapleProc(kv,ToMapleName(kv,"unapply",TRUE),2,args[1],

             MapleSelectIndexed(kv,indets,1,&i));

        if( !f || !IsMapleProcedure(kv,f) ) {

        MapleRaiseError(kv,"unable to convert first arg to a procedure");

        return( NULL );

        }

    }

    x = ToMapleName(kv,"x",FALSE);

    fprime = EvalMapleProc(kv,ToMapleName(kv,"unapply",TRUE),2,

            EvalMapleProc(kv,ToMapleName(kv,"diff",TRUE),2,

            ToMapleFunction(kv,f,1,x),x),x);

    if( !fprime || !IsMapleProcedure(kv,fprime) ) {

        MapleRaiseError(kv,"unable to compute derivative");

        return( NULL );

    }

    DoubleTohfData( kv, MapleEvalhf( kv, args[2] ), 0, guess+1 );

    tolerance = MapleEvalhf(kv,args[3]);

    res = 0.0;

    for( i=0; i<500; ++i ) {

        res = RealhfData( kv, EvalhfDataProc(kv,f,1,guess) );

        if( fabs( res ) <= tolerance )

        break;

        newguess = RealhfData( kv, guess[1] ) -

        res / RealhfData( kv, EvalhfDataProc(kv,fprime,1,guess) );

        DoubleTohfData( kv, newguess, 0, guess+1 );

    }

    if( i == 500 ) {

        MapleRaiseError(kv,"unable to find root after 500 iterations");

        return( NULL );

    }

    return( ToMapleFloat(kv, RealhfData( kv, guess[1] ) ) );

    }

Execute the external function from Maple.

withExternalCalling&colon;

dllExternalLibraryNameHelpExamples&colon;

newtonDefineExternalMyNewtonData&comma;dll&colon;

fx45x2+6x2&colon;

newtonf&comma;0&comma;0.001

0.731892751250226237

(1)

evalf&comma;x=

−0.000039355

(2)

newtonf&comma;sqrt2&comma;0.00001

1.00195003210012135

(3)

evalf&comma;x=

3.833×10−6

(4)

newtonf&comma;π&comma;1.×10−10

−2.73205080756887719

(5)

Digits15&colon;

evalf&comma;x=

1.5×10−13

(6)

funapplyf&comma;x&colon;

newtonf&comma;π&comma;1.×10−10

−2.73205080756887719

(7)

evalhff

−7.10542735760100186×10−15

(8)

See Also

CustomWrapper

define_external

evalhf

OpenMaple

OpenMaple/C/API

OpenMaple/C/ComplexTohfData

OpenMaple/C/DoubleTohfData

OpenMaple/C/Examples

OpenMaple/C/MapleTohfData

OpenMaple/C/RealhfData

OpenMaple/C/ToMaplehfData