Csound Csound-dev Csound-tekno Search About

[Cs-dev] how can this happen?

Date2010-08-23 16:25
FromVictor Lazzarini
Subject[Cs-dev] how can this happen?
  *p->hptr = (MYFLT) ((unsigned long)p->handle);
    csound->Message(csound, "handle %p => %u => %f => %x \n",
                p->handle, (unsigned long) p->handle, *p->hptr,  
(unsigned long) *p->hptr);

prints out....

handle 0x183473c8 => 406090696 => 406090688.000000 => 183473c0


why is this assignment being rounded up? (NB: MYFLT => float)

------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2010-08-23 16:35
FromRichard Dobson
SubjectRe: [Cs-dev] how can this happen?
On 23/08/2010 16:25, Victor Lazzarini wrote:
>    *p->hptr = (MYFLT) ((unsigned long)p->handle);
>      csound->Message(csound, "handle %p =>  %u =>  %f =>  %x \n",
>                  p->handle, (unsigned long) p->handle, *p->hptr,
> (unsigned long) *p->hptr);
>
> prints out....
>
> handle 0x183473c8 =>  406090696 =>  406090688.000000 =>  183473c0
>
>
> why is this assignment being rounded up? (NB: MYFLT =>  float)
>
A 32bit float only resolves to seven(-ish) accurate decimal digits, 
whatever the magnitude. The above maps a large 32bit int to a smaller 
float with at best 25bit precision.

Richard Dobson



------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2010-08-23 17:12
FromVictor Lazzarini
SubjectRe: [Cs-dev] how can this happen?
yes, I suspected overflow as I typed the e-mail...
On 23 Aug 2010, at 16:35, Richard Dobson wrote:

> On 23/08/2010 16:25, Victor Lazzarini wrote:
>>   *p->hptr = (MYFLT) ((unsigned long)p->handle);
>>     csound->Message(csound, "handle %p =>  %u =>  %f =>  %x \n",
>>                 p->handle, (unsigned long) p->handle, *p->hptr,
>> (unsigned long) *p->hptr);
>>
>> prints out....
>>
>> handle 0x183473c8 =>  406090696 =>  406090688.000000 =>  183473c0
>>
>>
>> why is this assignment being rounded up? (NB: MYFLT =>  float)
>>
> A 32bit float only resolves to seven(-ish) accurate decimal digits,
> whatever the magnitude. The above maps a large 32bit int to a smaller
> float with at best 25bit precision.
>
> Richard Dobson
>
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by
>
> Make an app they can't live without
> Enter the BlackBerry Developer Challenge
> http://p.sf.net/sfu/RIM-dev2dev
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel


------------------------------------------------------------------------------
This SF.net email is sponsored by 

Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev 
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net