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

Ian Haywood ihaywood3 at ...626...
Thu Apr 10 07:08:21 CEST 2014


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




More information about the User mailing list