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


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

Re: passing Indeterminate and Infinity to C via MathLink

From John Fultz <jfultz@wolfram.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: passing Indeterminate and Infinity to C via MathLink
Date 2011-09-12 08:23 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j4kfii$kes$1@smc.vnet.net> (permalink)

Show all headers | View raw


On Sat, 10 Sep 2011 07:29:23 -0400 (EDT), Roman wrote:
> Hello all,
> I am setting up a C function which accepts real numbers from MathLink.
> The behavior I would like to achieve is that whenever the number is
> "Infinity" then the C function receives "inf" (which is a valid double-
> precision-format number); and whenever the number is "Indeterminate"
> then the C function receives "nan" (which is also a valid double-
> precision-format number).
> Unfortunately MathLink (Mathematica 7.0 for Mac OS X x86 (64-bit))
> crashes whenever I am trying to pass either Infinity or Indeterminate
> to a MathLink function expecting a double-precision number.
> Would you know how to solve this without going into If[] statements on
> the Mathematica side of MathLink?
> Thanks!
> Roman

Mathematica represents Indeterminate and Infinity as symbols in its expression 
tree, and MathLink is always very faithful about transmitting the expression 
tree precisely.  Note that it's not very difficult to deal with this in your C 
code, though.  You can just declare the function as having a Manual MathLink 
type and then, in the C function determine using MLGetNext() whether the next 
thing is a symbol or a real.  If it's a symbol, then you can just synthesizes 
the IEEE version of the indeterminate value in your C program.

About two thirds of the way down this help page:

tutorial/HandlingListsArraysAndOtherExpressions

there's an example that illustrates how to use Manual as an argument type.

Sincerely,

John Fultz
jfultz@wolfram.com
User Interface Group
Wolfram Research, Inc.

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


Thread

Re: passing Indeterminate and Infinity to C via MathLink John Fultz <jfultz@wolfram.com> - 2011-09-12 08:23 +0000
  Re: passing Indeterminate and Infinity to C via MathLink Roman <rschmied@gmail.com> - 2011-09-15 08:49 +0000

csiph-web