Square Root function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yueying53
    New Member
    • Dec 2008
    • 13

    Square Root function

    Hi guys,

    For some reason, the hardware that i'm working with cannot import sqrt from math. Hence I need to manually write a sqrt function. Been searching everywhere to find such a function but to no avail.

    Could any kind soul please help me with this!

    THanks a million!

    Sam
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Good news, Sam! Python has a built-in power operator.
    Code:
    >>> 2**2
    4
    >>> 2**0.5
    1.4142135623730951
    >>>

    Comment

    • yueying53
      New Member
      • Dec 2008
      • 13

      #3
      Hi,

      Thanks for replying! Unfortunately I am using python to program a Telit GSM modem. I write the program on my computer, run it on python, and it works. But as soon as I upload the program into the internal memory of the modem, things go wrong. For one, it cannot work with floats, and apparently sqrt doesn't work too.

      Hence I'm trying to manually write a sqrt function to get around the problem.

      Thanks for your time!

      Regards,
      Sam

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        Sam,

        A google search using "square root calculation algorithm" produced a list of several web pages that explains how to calculate a square root manually.

        Comment

        • yueying53
          New Member
          • Dec 2008
          • 13

          #5
          Hi bvdet,

          Thanks for your suggestions! I guess I was googling with the wrong key words that's why I didn't get anything on my first try. Anyway, I've found the webpages that you were talking about to be very useful.

          Thanks a million!

          Cheers, Sam

          Comment

          Working...