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

Jussi Lahtinen jussi.lahtinen at ...626...
Thu Apr 10 16:50:02 CEST 2014


That is completely expected just try:
Print csingle(180.2)
180,1999969

You cannot express 180.2 precisely with 32 bits.
Even with 64 bits it's something like: 180.199999999999988631 ...


Jussi



On Thu, Apr 10, 2014 at 7:43 AM, Kevin Fishburne <
kevinfishburne at ...1887...> wrote:

> I have an array (Plan) of a structure (PlanStructure) which contains
> several other structures (PlanPortalStructure, etc.):
>
>     ' Architectural plan portal structure (server).
>     Public Struct PlanPortalStructure
>        PlanX As Short        ' Position in architectural plan.
>        PlanY As Short        ' Position in architectural plan.
>        Created As Boolean    ' If portal PWO has already been created.
>        Skin As Short         ' Portal skin.
>        Orientation As Single ' Portal orientation.
>     End Struct
>
>     ' Architectural plan structure (server).
>     Public Struct PlanStructure
>        Stage As Byte                           ' Current build stage (0
>     = design, 1 = clear and grade, 2 = wall construction, 3 = roofing
>     construction, 4 = flooring construction, 5 = lighting installation,
>     6 = finished/maintenance).
>        Index As Integer                        ' Current position in
>     block type array.
>        GradingTarget As Long                   ' Elevation in inches to
>     grade landscape and/or create block PWOs at.
>        CenterX As Integer                      ' Build site center
>     coordinate.
>        CenterY As Integer                      ' Build site center
>     coordinate.
>        Grading As PlanGradingStructure[]       ' Grading blocks.
>        Wall As PlanWallStructure[]             ' Wall blocks.
>        Roofing As PlanRoofingStructure[]       ' Roofing blocks.
>        Flooring As PlanFlooringStructure[]     ' Flooring blocks.
>        Lighting As PlanLightingStructure[]     ' Lighting blocks.
>        Portal As PlanPortalStructure[]         ' Portal blocks.
>        Furnishing As PlanFurnishingStructure[] ' Furnishing blocks.
>        WallHeightTallest As Single             ' Maximum wall target
>     height (temporarily used to set roofing height).
>        WallHeightTotal As Single               ' Total height in feet of
>     all walls (used to know when wall construction has been completed).
>        WallHeightCurrent As Single             ' Current height in feet
>     of all walls constructed (used to know when wall construction has
>     been completed).
>     End Struct
>     Public Plan[10] As Struct PlanStructure
>
>
> When I assign the value 180.2 to the Orientation property (type Single)
> of PlanPortalStructure like this:
>
>     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?
>
> --
> Kevin Fishburne
> Eight Virtues
> www: http://sales.eightvirtues.com
> e-mail: sales at ...1887...
> phone: (770) 853-6271
>
>
>
> ------------------------------------------------------------------------------
> 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