Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: passing Indeterminate and Infinity to C via MathLink

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121620] Re: passing Indeterminate and Infinity to C via MathLink
  • From: Richard Fateman <fateman at cs.berkeley.edu>
  • Date: Thu, 22 Sep 2011 07:27:11 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j4fhpt$2g7$1@smc.vnet.net>

On 9/10/2011 4:31 AM, 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
>
I think that the explanations have said what Mathematica can do, and it 
is unfortunately that there is no floating point sized object that you 
can use to encode and transmit an IEEE-inf or IEEE-NaN in a packed 
array in Mathematica.

Just to correct your statement above, "NaN" is not really a valid 
double-precision-format number.  It is "not a number", but it fits in 
the same space as a valid double-precision-format number, 64 bits. There 
are many possible NaNs  (a NaN has an illegal exponent; any fraction 
part is OK, and it can be used to store info.) Inf is also not a valid 
"number".

In other programs such as Mathematica where arbitrary sized objects can 
play ball with numbers, these IEEE representations are not "needed". 
However there does not seem to be any principle which forbids them from 
being created, printed, and passed to programs for which they are used.
Your situation, where these special forms are passed to a numeric 
program, is an excellent example.

RJF





  • Prev by Date: Re: Calculus and InterpolatingFunction
  • Next by Date: Re: Calculus and InterpolatingFunction
  • Previous by thread: Re: passing Indeterminate and Infinity to C via MathLink
  • Next by thread: help to make code run faster (mathematica v8.01)