[LCP]puzzling

Anandakumar.Thangaraju at EchoMail.com Anandakumar.Thangaraju at EchoMail.com
Fri Feb 28 18:04:02 UTC 2003


Go thru the following modified application. Instead of working with
original expressions, I assigned the value to Double var and added a
function LBinary to print the Binary representation of given long. By this
we can learn that printf is just doing a BLIND printing of given address to
the given type. To assert that I copied the first 4 byte of the double to a
long variable. As expected the binary representation of long "1202590843"
and the 4 byte copied are same.

#include <memory.h>

void LBinary(unsigned long No)
{

     unsigned long Mask = 1<<31;

     for (int index=0;index<32;index++, Mask>>=1)
     {
          if (No & Mask)
               printf("1");
          else
               printf("0");
     }

}


void main()
{
       long          t;
       double   d = 3065.4400;   // This is result of your original
Expression.

       printf("\nDouble as Long = %ld",d);
       printf("\nDouble as Double = %f",d);

       // Move the first 4 Bytes of the Double (8 byte) to Long
       // Note : No casting is done here.. we're doing DUMP transfer

       memcpy((void*)&t, (void*)&d, 4);

       printf("\nBinary for Long (1202590843)   : "); LBinary(1202590843);
       printf("\nBinary for T                   : "); LBinary(t);

       printf("\n");
}

Regards,
Anandakumar Thangaraju,
Millennium Software Productions (India) Pvt Ltd,
1, Kuppusamy Street,
T.Nagar, Chennai-600017.
Tel   : 28157724/25  x 124
Mail  : anandakumar at echomail.com


                                                                                                                                     
                    Kurian Abraham Kurian                                                                                            
                    Abraham-A18108                         To:     linuxcprogramming at lists.linux.org.au                              
                    <kurian.abraham at motorola.com>          cc:                                                                       
                    Sent by:                               Subject:     [LCP]puzzling                                                
                    linuxcprogramming-admin at lists.li                                                                                 
                    nux.org.au                                                                                                       
                                                                                                                                     
                                                                                                                                     
                    02/24/03 11:37 AM                                                                                                
                    Please respond to                                                                                                
                    linuxcprogramming                                                                                                
                                                                                                                                     
                                                                                                                                     




hi

i have a question.....
int main()
{
  long       a = 13;
  long       b = 197;
  long       c ;

  c = (b-a)*16.66;
  printf("\nAmazing = %ld",(b - a)*(16.66));
  printf("\nC is %ld\n",c);
  return 0;
}

pls run this program....and tell me why the answers r different?

thanx & regds
kurian
_______________________________________________
This is the Linux C Programming List
:  http://lists.linux.org.au/listinfo/linuxcprogramming List






More information about the linuxCprogramming mailing list