       Re: Machine-precision Exp[] function

• To: mathgroup at smc.vnet.net
• Subject: [mg93621] Re: [mg93572] Machine-precision Exp[] function
• From: DrMajorBob <btreat1 at austin.rr.com>
• Date: Tue, 18 Nov 2008 07:21:44 -0500 (EST)
• References: <200811151103.GAA16550@smc.vnet.net>

```How about

Exp[-1.*^6] // N

3.296831478*10^-434295

It's not zero, but likely close enough for your purposes. You could also
define

nExp=Chop@Exp@#&;

and use nExp in place of Exp.

Or you could apply Chop anywhere you suspect near-zeroes might have crept
into calculations, without allowing the issue to slow down ALL computation.

Bobby

On Sat, 15 Nov 2008 05:03:08 -0600, Roman <rschmied at gmail.com> wrote:

> Hi all,
>
> The built-in Exp[] function is a bit too smart for my purposes, since
> it generates arbitrary-precision results if machine-precision numbers
> cannot hold the result. For instance,
>    In := Exp[-1`*^6]
>    Out =
> 3.296831478088558578968907969112477365`9.954589770191001*^-434295
> produces a number for which MachineNumberQ[] returns False. Such non-
> machine-precision numbers massively slow down my program without
> actually making any difference in accuracy at the end. So I need a
> function, MachineNumberExp[], which *always* spits out a machine-
> precision number; underflows would be replaced by zeroes:
>    In := MachinePrecisionExp[-1`*^6]
>    Out = 0.
> Is such a function already built into Mathematica? I.e., is there a
> way to switch off the underflow-treatment behavior of calculating
> arbitrary-precision results?
>
> I know I can define
> MachinePrecisionExp[x_?MachineNumberQ] := If[Re[x] >= -708, Exp[x],
> 0.]
> but I'm looking for efficient, built-in, machine-precision procedures
> since my code is supposed to be blazing fast at the end.
>
> Roman.
>

--
DrMajorBob at longhorns.com

```

• Prev by Date: Linear algebra with generic dimensions
• Next by Date: Re: Working with vectors symbolically
• Previous by thread: Machine-precision Exp[] function
• Next by thread: Re: Machine-precision Exp[] function