1. printf() on decimals

Try this:

printf(1, "%.16g\n", 1999999999999990)
printf(1, "%.16g\n", 2999999999999990)
printf(1, "%.16g\n", 3999999999999990)
printf(1, "%.16g\n", 4999999999999990)
printf(1, "%.16g\n", 5999999999999990)
printf(1, "%.16g\n", 6999999999999990)
printf(1, "%.16g\n", 7999999999999990)
printf(1, "%.16g\n", 8999999999999990)
printf(1, "%.16g\n", 9999999999999990)


Why is the last line printed differently?

new topic     » topic index » view message » categorize

2. Re: printf() on decimals

Prints what differently? They look the same to me.

Using exu on RedHat 7.2 with kernel 2.4.18.

jbrown

On Mon, Jun 30, 2003 at 11:01:27PM +0700, aku saya wrote:
> 
> 
> Try this:
> 
> printf(1, "%.16g\n", 1999999999999990)
> printf(1, "%.16g\n", 2999999999999990)
> printf(1, "%.16g\n", 3999999999999990)
> printf(1, "%.16g\n", 4999999999999990)
> printf(1, "%.16g\n", 5999999999999990)
> printf(1, "%.16g\n", 6999999999999990)
> printf(1, "%.16g\n", 7999999999999990)
> printf(1, "%.16g\n", 8999999999999990)
> printf(1, "%.16g\n", 9999999999999990)
> 
> 
> Why is the last line printed differently?
> 
> 
> 
> TOPICA - Start your own email discussion group. FREE!
> 
> 

-- 
 /"\  ASCII ribbon              | http://www.geocities.com/jbrown1050/
 \ /  campain against           | Linux User:190064
  X   HTML in e-mail and        | Linux Machine:84163
 /*\  news, and unneeded MIME   | http://verify.stanford.edu/evote.html

new topic     » goto parent     » topic index » view message » categorize

3. Re: printf() on decimals

aku saya wrote:
> 
> 
> Try this:
> 
> printf(1, "%.16g\n", 1999999999999990)
> printf(1, "%.16g\n", 2999999999999990)
> printf(1, "%.16g\n", 3999999999999990)
> printf(1, "%.16g\n", 4999999999999990)
> printf(1, "%.16g\n", 5999999999999990)
> printf(1, "%.16g\n", 6999999999999990)
> printf(1, "%.16g\n", 7999999999999990)
> printf(1, "%.16g\n", 8999999999999990)
> printf(1, "%.16g\n", 9999999999999990)
> 
> 
> Why is the last line printed differently?

My guess is that you reached the limit of single precision floating point.

Ray

new topic     » goto parent     » topic index » view message » categorize

4. Re: printf() on decimals

> Try this:
>
> printf(1, "%.16g\n", 1999999999999990)
> printf(1, "%.16g\n", 2999999999999990)
> printf(1, "%.16g\n", 3999999999999990)
> printf(1, "%.16g\n", 4999999999999990)
> printf(1, "%.16g\n", 5999999999999990)
> printf(1, "%.16g\n", 6999999999999990)
> printf(1, "%.16g\n", 7999999999999990)
> printf(1, "%.16g\n", 8999999999999990)
> printf(1, "%.16g\n", 9999999999999990)
>
>
> Why is the last line printed differently?

ex.exe produced:

1999999999999990
2999999999999990
3999999999999990
4999999999999990
5999999999999990
6999999999999990
7999999999999990
8999999999999990
9999999999999990

however, exw.exe produced:

1999999999999990
2999999999999990
3999999999999990
4999999999999990
5999999999999990
6999999999999990
7999999999999990
8999999999999990
9.99999999999999e+015

i assume this has to do with how windows handles floating-point math as
opposed to dos and 'nix.

new topic     » goto parent     » topic index » view message » categorize

5. Re: printf() on decimals

> aku saya wrote:
>  
>  Try this:
>  
>  printf(1, "%.16g\n", 1999999999999990)
>  printf(1, "%.16g\n", 2999999999999990)
>  printf(1, "%.16g\n", 3999999999999990)
>  printf(1, "%.16g\n", 4999999999999990)
>  printf(1, "%.16g\n", 5999999999999990)
>  printf(1, "%.16g\n", 6999999999999990)
>  printf(1, "%.16g\n", 7999999999999990)
>  printf(1, "%.16g\n", 8999999999999990)
>  printf(1, "%.16g\n", 9999999999999990)
>  
>  Why is the last line printed differently?

1999999999999990
2999999999999990
3999999999999990
4999999999999990
5999999999999990
6999999999999990
7999999999999990
8999999999999990
9999999999999990

Press Enter...

The last line looks ok to me. What are we looking for?

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

6. Re: printf() on decimals

aku saya wrote:
> Try this:
> 
> printf(1, "%.16g\n", 1999999999999990)
> printf(1, "%.16g\n", 2999999999999990)
> printf(1, "%.16g\n", 3999999999999990)
> printf(1, "%.16g\n", 4999999999999990)
> printf(1, "%.16g\n", 5999999999999990)
> printf(1, "%.16g\n", 6999999999999990)
> printf(1, "%.16g\n", 7999999999999990)
> printf(1, "%.16g\n", 8999999999999990)
> printf(1, "%.16g\n", 9999999999999990)
> 
> 
> Why is the last line printed differently?

With %g format you are giving printf some freedom
to choose how it displays floating-point numbers.
I guess exw.exe chose differently for the last one,
probably because it's so close to 1000000....
Euphoria relies on C's printf routine,
and each C library is a bit different.
I can't control details like this without
writing my own full-blown replacement for C's printf.

Regards,
    Rob Craig
    Rapid Deployment Software
    http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu