www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - 'real' not able to store it's largest value

reply colin <grogan.colin gmail.com> writes:
Am I doing something wrong here?

real.max evaluates to: 1.18973e+4932

So, I'd expect to be able to store any value up to that... however
```
void main()
{
     writeln("Real max: ", real.max);
     foreach(i; 0..10){
         writefln!("1024 ^^ %s = %s")(i, real(1024 ^^ i));
     }
}

```
Output:
```
Real max: 1.18973e+4932
1024 ^^ 0 = 1
1024 ^^ 1 = 1024
1024 ^^ 2 = 1.04858e+06
1024 ^^ 3 = 1.07374e+09
1024 ^^ 4 = 0
1024 ^^ 5 = 0
1024 ^^ 6 = 0
1024 ^^ 7 = 0
1024 ^^ 8 = 0
1024 ^^ 9 = 0
```
May 22 2017
next sibling parent Adam D. Ruppe <destructionator gmail.com> writes:
On Monday, 22 May 2017 at 20:26:27 UTC, colin wrote:
         writefln!("1024 ^^ %s = %s")(i, real(1024 ^^ i));
You convert to real AFTER doing the exponent on an integer. change `real(1024 ^^ i)` to `real(1024) ^^ i` and you should get a different result.
May 22 2017
prev sibling parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 05/22/2017 01:26 PM, colin wrote:
 Am I doing something wrong here?

 real.max evaluates to: 1.18973e+4932

 So, I'd expect to be able to store any value up to that... however
 ```
 void main()
 {
     writeln("Real max: ", real.max);
     foreach(i; 0..10){
         writefln!("1024 ^^ %s = %s")(i, real(1024 ^^ i));
Like some other languages, expressions are mostly evaluated in isolation. 1024 ^^ i is an int, which cannot represent anything close to real.max. :) This should work: real(1024) ^^ i Ali
May 22 2017
parent colin <grogan.colin gmail.com> writes:
D'oh!

Thanks Adam and Ali :)
May 22 2017