×

Discussion Board

Results 1 to 4 of 4

Thread: Floating point

  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    26

    Floating point

    Hello,

    What's the best practice for using floating point numbers in pys60 1.9.2? For example division of two integer values converted to float does not give a sensible result (float(12345)/n gives 2.46..).

    Using decimal seems to solve the problem partially, but printing the values also sometimes outputs results in the same way (and decimal is much slower).

    Any suggestions how to operate floating point numbers retaining reasonable accuracy?

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: Floating point

    A few examples of what the result is and what you want the result to look like might help us understand the situation better.

  3. #3
    Registered User
    Join Date
    Jun 2009
    Posts
    26

    Re: Floating point

    Basically, having a list of integer values I need to find mean and standard deviation of them.

    Example -
    [3597, 3473, 3454, 3444, 3444, 3444, 3570, 3689, 3717, 3617, 3521, 3406, 3429, 3418, 3533, 3454, 3454, 3454, 3454, 3329, 3442, 3419, 3549, 3549, 3474, 3474, 3474, 3572, 3534, 3521, 3521, 3557, 3549, 3413, 3413, 3513, 3500, 3534, 3549, 3549, 3534, 3500, 3489, 3618, 3627, 3500, 3617, 3481, 3481, 3481, 3500, 3651, 3500, 3500, 3500, 3500, 3500, 3534, 3534, 3534, 3534, 3534, 3534, 3442, 3557, 3582, 3582, 3582, 3557, 3572, 3572, 3549, 3534, 3534, 3528, 3528, 3528, 3513, 3500, 3481, 3500, 3500, 3521, 3521, 3521, 3521, 3521, 3544, 3557, 3557, 3557, 3557, 3572, 3557, 3557, 3557, 3674, 3557, 3674, 3544]

    Using float function mean gives "3.52.." (where it should be 3524)
    And stdev gives "63..737663375194" (should be 63.0737663375194)

    The values actually seem to be the same, but I can't find a way to print them out in a readable way (let's say 3524.0000 and 63.0738).
    One possible way is to use decimal module, but it seems to be much slower even than floating point.

    mean and stdev defined as:

    def mean(data):
    n = len(data)
    sum = 0
    for item in data:
    sum = sum+item
    return float(sum)/n

    def stdev(data, mean):
    n = len(data)
    sum = 0
    for item in data:
    sum = sum+(item-mean)*(item-mean)
    t = sum/n
    return sqrt(t)


    stdev is called stdev(data, mean(data))

  4. #4
    Regular Contributor
    Join Date
    Oct 2007
    Posts
    114

    Re: Floating point

    Quote Originally Posted by AndriusA View Post
    And stdev gives "63..737663375194" (should be 63.0737663375194)
    Looking at the double dot I am guessing this is related to the OpenC bug which was present one of the old 1.9.x release. Can you please upgrade to the latest PyS60 1.9.5 release and then check?
    import antigravity

Similar Threads

  1. how to use floating point operation in J2ME CLDC 1.0
    By arungupta_2jan in forum Mobile Java General
    Replies: 4
    Last Post: 2009-05-28, 12:07
  2. how to create Floating Point and Fixed point editor?
    By rohanwaugh in forum Symbian User Interface
    Replies: 5
    Last Post: 2008-12-18, 07:25
  3. Immortal floating point
    By maciekj in forum Mobile Java General
    Replies: 1
    Last Post: 2007-11-28, 23:50
  4. floating point vs fixed point math
    By DanielMD in forum Mobile Java General
    Replies: 9
    Last Post: 2004-03-24, 18:21
  5. Floating point numbers / Angle between points
    By Pandaemonium in forum Mobile Java General
    Replies: 8
    Last Post: 2004-03-10, 16:02

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×