[Mono-dev] Simple floating maths problem

Stuart Fraser stuart at stuartfraser.net
Fri Apr 30 06:46:30 EDT 2010


Hi Andreas,

Thanks for the feedback, I've just been looking it up in the spec. For the time being it this is a synthetic test so not an immediate problem but the values being calculated in the real code are actually indices into a sparse matrix - getting the wrong index is not an option!  For use in HPC / Scientific codes this functionality will have to be correct, so I'm going to dig a little further. 

Any pointers would be helpful,

Many thanks
S


> -----Original Message-----
> From: Andreas Nahr [mailto:ClassDevelopment at A-SoftTech.com]
> Sent: 30 April 2010 11:15
> To: Stuart Fraser; mono-devel-list at lists.ximian.com
> Subject: AW: [Mono-dev] Simple floating maths problem
> 
> I just tried your sample and if you are looking for a quick workaround (for
> yourself, not mono) remove the explicit int cast:
> 
>             int fact = 50000;
>             float[] tList = { 0.95864f, 0.89374f, 0.89092f, 0.89716f, 0.4191f, 0.79782f };
> 
>             foreach (float val in tList)
>             {
>                 float comp = val * fact;
>                 Console.WriteLine("{0:g} * {1:d} = {2}", val, fact, comp);
>             }
> 
> BTW: If you are looking for something with high precision then float is no
> good choice. .Net/Mono has a Decimal type that offers high precision with
> acceptable performance.
> 
> 
> __________________________________________________________
> ____________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> __________________________________________________________
> ____________

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


More information about the Mono-devel-list mailing list