digitalmars.D.learn - 'real' not able to store it's largest value
- colin (26/26) May 22 2017 Am I doing something wrong here?
- Adam D. Ruppe (4/5) May 22 2017 You convert to real AFTER doing the exponent on an integer.
- =?UTF-8?Q?Ali_=c3=87ehreli?= (7/16) May 22 2017 Like some other languages, expressions are mostly evaluated in
- colin (2/2) May 22 2017 D'oh!
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
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
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









Adam D. Ruppe <destructionator gmail.com> 