Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Square function?

Square function?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chambers
    wrote on last edited by
    #1

    What is the square function in VC++? I have tried using : pow(a, 2); but its ridiculously slow (i need to perform many such calculations), now i`ve just got (a*a) instead (which is crap loads quicker). I just need to know that I`ve gone about it the right way. Cheers all, Alan.:-D AEGC

    N 1 Reply Last reply
    0
    • C Chambers

      What is the square function in VC++? I have tried using : pow(a, 2); but its ridiculously slow (i need to perform many such calculations), now i`ve just got (a*a) instead (which is crap loads quicker). I just need to know that I`ve gone about it the right way. Cheers all, Alan.:-D AEGC

      N Offline
      N Offline
      Nish Nishant
      wrote on last edited by
      #2

      The fastest way to calculate the square of a number would be to use the * operator as you have already tried out. When you do a*a that's about the best you can do. Because it translates into the MUL instructions directly. But if you want to do floating point squaring then I am not sure. Perhaps you could try using logarithms [which involve addtitions and not multiplications] which might speed up things. In the DOS days I remember how we used to set the compiler/linker options to generate 80x87 code that speeded up the mathematics. I wonder whether there is some such thing for win32 stuff too. Regards Nish Sonork ID 100.9786 voidmain

      C 1 Reply Last reply
      0
      • N Nish Nishant

        The fastest way to calculate the square of a number would be to use the * operator as you have already tried out. When you do a*a that's about the best you can do. Because it translates into the MUL instructions directly. But if you want to do floating point squaring then I am not sure. Perhaps you could try using logarithms [which involve addtitions and not multiplications] which might speed up things. In the DOS days I remember how we used to set the compiler/linker options to generate 80x87 code that speeded up the mathematics. I wonder whether there is some such thing for win32 stuff too. Regards Nish Sonork ID 100.9786 voidmain

        C Offline
        C Offline
        Chambers
        wrote on last edited by
        #3

        Many thanks Nish. I needed to know that that was the best (quickest) way of going about squaring a variable (integers). Thanks again, Alan.:-D AEGC

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups