www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - issue with inf from exp function

reply Matt Gamble <gamblemj gmail.com> writes:
I don't understand why I'm getting an 'inf' by raising E to a 
real number, e^^710.0L. See below.

import std.stdio;
import std.math;

unittest
{
	writefln("ln(largest double) = %s", log(double.max)); // 709.783
	writefln("e^710 = %s", exp(710.0));// inf, makes sense

	writefln("ln(largest real) = %s", log(real.max)); // 11356.6
	real t = 710.0;
	writefln("e^710 = %s", exp(t)); //why is this inf???
}

Any help would be greatly appreciated. I have functions in an 
actual program that are giving me a headache due to this issue.
Mar 07 2018
parent reply Alex <sascha.orlov gmail.com> writes:
On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote:
 I don't understand why I'm getting an 'inf' by raising E to a 
 real number, e^^710.0L. See below.

 import std.stdio;
 import std.math;

 unittest
 {
 	writefln("ln(largest double) = %s", log(double.max)); // 
 709.783
 	writefln("e^710 = %s", exp(710.0));// inf, makes sense

 	writefln("ln(largest real) = %s", log(real.max)); // 11356.6
 	real t = 710.0;
 	writefln("e^710 = %s", exp(t)); //why is this inf???
 }

 Any help would be greatly appreciated. I have functions in an 
 actual program that are giving me a headache due to this issue.
works for me as expected. ln(largest double) = 709.783 e^710 = inf ln(largest real) = 11356.5 e^710 = 2.23399e+308
Mar 07 2018
next sibling parent reply Matt Gamble <gamblemj gmail.com> writes:
On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote:
 On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote:
 I don't understand why I'm getting an 'inf' by raising E to a 
 real number, e^^710.0L. See below.

 import std.stdio;
 import std.math;

 unittest
 {
 	writefln("ln(largest double) = %s", log(double.max)); // 
 709.783
 	writefln("e^710 = %s", exp(710.0));// inf, makes sense

 	writefln("ln(largest real) = %s", log(real.max)); // 11356.6
 	real t = 710.0;
 	writefln("e^710 = %s", exp(t)); //why is this inf???
 }

 Any help would be greatly appreciated. I have functions in an 
 actual program that are giving me a headache due to this issue.
works for me as expected. ln(largest double) = 709.783 e^710 = inf ln(largest real) = 11356.5 e^710 = 2.23399e+308
Really? Is it my system? I'm running windows 10, with an intel Core i7-4650, 64bit operating system I compiled with -m64 -g -unittest -main
Mar 07 2018
parent Marc <jckj33 gmail.com> writes:
On Wednesday, 7 March 2018 at 16:06:26 UTC, Matt Gamble wrote:
 On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote:
 On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote:
 [...]
works for me as expected. ln(largest double) = 709.783 e^710 = inf ln(largest real) = 11356.5 e^710 = 2.23399e+308
Really? Is it my system? I'm running windows 10, with an intel Core i7-4650, 64bit operating system I compiled with -m64 -g -unittest -main
Did notice you were using -m64 flag before. Well, now I used -m64 the same code doesn't work as expected. I also got inf.
Mar 07 2018
prev sibling parent reply Marc <jckj33 gmail.com> writes:
On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote:
 On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote:
 I don't understand why I'm getting an 'inf' by raising E to a 
 real number, e^^710.0L. See below.

 import std.stdio;
 import std.math;

 unittest
 {
 	writefln("ln(largest double) = %s", log(double.max)); // 
 709.783
 	writefln("e^710 = %s", exp(710.0));// inf, makes sense

 	writefln("ln(largest real) = %s", log(real.max)); // 11356.6
 	real t = 710.0;
 	writefln("e^710 = %s", exp(t)); //why is this inf???
 }

 Any help would be greatly appreciated. I have functions in an 
 actual program that are giving me a headache due to this issue.
works for me as expected. ln(largest double) = 709.783 e^710 = inf ln(largest real) = 11356.5 e^710 = 2.23399e+308
it works for me too. https://imgur.com/bLGTv1l
Mar 07 2018
parent reply Matt Gamble <gamblemj gmail.com> writes:
On Wednesday, 7 March 2018 at 16:10:15 UTC, Marc wrote:
 On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote:
 On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote:
 [...]
works for me as expected. ln(largest double) = 709.783 e^710 = inf ln(largest real) = 11356.5 e^710 = 2.23399e+308
it works for me too. https://imgur.com/bLGTv1l
Wow, Now I'm really confused, I'm using DMD v2.076.1. Any thoughts I why I'm getting this result?
Mar 07 2018
next sibling parent Marc <jckj33 gmail.com> writes:
On Wednesday, 7 March 2018 at 16:12:28 UTC, Matt Gamble wrote:
 On Wednesday, 7 March 2018 at 16:10:15 UTC, Marc wrote:
 On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote:
 On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote:
 [...]
works for me as expected. ln(largest double) = 709.783 e^710 = inf ln(largest real) = 11356.5 e^710 = 2.23399e+308
it works for me too. https://imgur.com/bLGTv1l
Wow, Now I'm really confused, I'm using DMD v2.076.1. Any thoughts I why I'm getting this result?
See my previous post. It's something related to generating 64bit code.
Mar 07 2018
prev sibling parent reply Matt Gamble <gamblemj gmail.com> writes:
On Wednesday, 7 March 2018 at 16:12:28 UTC, Matt Gamble wrote:
 On Wednesday, 7 March 2018 at 16:10:15 UTC, Marc wrote:
 On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote:
 On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote:
 [...]
works for me as expected. ln(largest double) = 709.783 e^710 = inf ln(largest real) = 11356.5 e^710 = 2.23399e+308
it works for me too. https://imgur.com/bLGTv1l
Wow, Now I'm really confused, I'm using DMD v2.076.1. Any thoughts I why I'm getting this result?
Yes if I switch to 32bit, it works for me now. Is this a bug?
Mar 07 2018
parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 3/7/18 11:19 AM, Matt Gamble wrote:
 On Wednesday, 7 March 2018 at 16:12:28 UTC, Matt Gamble wrote:
 On Wednesday, 7 March 2018 at 16:10:15 UTC, Marc wrote:
 On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote:
 On Wednesday, 7 March 2018 at 15:44:28 UTC, Matt Gamble wrote:
 [...]
works for me as expected. ln(largest double) = 709.783 e^710 = inf ln(largest real) = 11356.5 e^710 = 2.23399e+308
it works for me too. https://imgur.com/bLGTv1l
Wow, Now I'm really confused, I'm using DMD v2.076.1. Any thoughts I why I'm getting this result?
Yes if I switch to 32bit, it works for me now. Is this a bug?
Looks like it. The core.stdc.math module looks very cryptic, but appears to do some weird things via exp on real. -Steve
Mar 07 2018
parent Matt Gamble <gamblemj gmail.com> writes:
On Wednesday, 7 March 2018 at 16:40:04 UTC, Steven Schveighoffer 
wrote:
 On 3/7/18 11:19 AM, Matt Gamble wrote:
 On Wednesday, 7 March 2018 at 16:12:28 UTC, Matt Gamble wrote:
 On Wednesday, 7 March 2018 at 16:10:15 UTC, Marc wrote:
 On Wednesday, 7 March 2018 at 16:00:39 UTC, Alex wrote:
 [...]
it works for me too. https://imgur.com/bLGTv1l
Wow, Now I'm really confused, I'm using DMD v2.076.1. Any thoughts I why I'm getting this result?
Yes if I switch to 32bit, it works for me now. Is this a bug?
Looks like it. The core.stdc.math module looks very cryptic, but appears to do some weird things via exp on real. -Steve
Thanks. I submitted as a bug. https://issues.dlang.org/show_bug.cgi?id=18570
Mar 07 2018