Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #2548

MLGetReal(Double) Problem in MathLink

From Soroush Heidari Pahlavian <shp_maya@yahoo.com>
Newsgroups comp.soft-sys.math.mathematica
Subject MLGetReal(Double) Problem in MathLink
Date 2011-05-21 10:45 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <ir853p$bav$1@smc.vnet.net> (permalink)

Show all headers | View raw


When I change the simple addtwo program in order to work with Real(Double)
numbers instead of Integer ones, the answer goes wrong (4+5 = -143566321 !).
What is the problem with the following code?
Thanks....
***************************************************************
#include <stdio.h>
#include "mathlink.h"

int main( int argc, char* argv[])
{
    double a, b;
    double ans;

    MLINK lp;
    MLEnvironment env;
    printf( "Enter two doubles: a and b\n\t" );
    scanf( "%d %d", &a, &b);
    env = MLInitialize(NULL);
    if(env == NULL) return 1;
    lp = MLOpen(argc, argv);
    if(lp == NULL) return 1;

    MLPutFunction(lp, "Plus", 2);
        MLPutDouble(lp, a);
        MLPutDouble(lp, b);
    MLEndPacket(lp);

    /* skip any packets before the first ReturnPacket */
    while (MLNextPacket(lp) != RETURNPKT) MLNewPacket(lp);
   
    MLGetDouble(lp, &ans);
    printf( "ans = %d\n", ans);
    MLClose(lp);
    MLDeinitialize(env);
    return 0;
}

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

MLGetReal(Double) Problem in MathLink Soroush Heidari Pahlavian <shp_maya@yahoo.com> - 2011-05-21 10:45 +0000

csiph-web