[Gambas-user] Precision immediately lost when assigning value to type Single structure property

Fabien Bodard gambas.fr at ...626...
Thu Apr 10 12:57:42 CEST 2014


Or store the value as integer an then divide by 10 on use
Le 10 avr. 2014 07:09, "Ian Haywood" <ihaywood3 at ...626...> a écrit :

> On Thu, Apr 10, 2014 at 2:43 PM, Kevin Fishburne
> <kevinfishburne at ...1887...> wrote:
> > I have an array (Plan) of a structure (PlanStructure) which contains
> > several other structures (PlanPortalStructure, etc.):
>
> >     Plan[p].Portal[Index].Orientation = 180.2
> >
> >
> > the value is assigned as 180.1999969.
> >
> > Any idea why this is happening?Seems strange that explicitly setting a
> > type Single to a value would immediately cause precision to be lost;
> > maybe it has to do with a structure being embedded in another structure?
> i doubt structures are the issue. floating point values are stored in
> binary internally so there is a translation between decimal for humans
> and binary which imparts a slight rounding error
> can you try Double: this won't fix the problem but will reduce it at a
> cost of more RAM
>
> if you need 100% decimal accuracy (it's usually only high-end
> financial stuff where you do), then look at gb.gmp component. Again it
> will cost you in RAM and speed.
>
> Ian
>
>
> ------------------------------------------------------------------------------
> Put Bad Developers to Shame
> Dominate Development with Jenkins Continuous Integration
> Continuously Automate Build, Test & Deployment
> Start a new project now. Try Jenkins in the cloud.
> http://p.sf.net/sfu/13600_Cloudbees
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list