java help plz =\

Discussion in 'OT Technology' started by philvia, Mar 29, 2009.

  1. philvia

    philvia SUCKIN ON MY TITTIES LIKE YOU WANTIN ME CALLIN ME

    Joined:
    May 3, 2007
    Messages:
    11,619
    Likes Received:
    0
    Location:
    NYC
    I have to make 2 programs... for now i'll just give you one...

    we have to program a way to find the square root without using math.sqrt(0);
    i've found out ways to do it manually with pen and paper... but the way i see it, programming it that way is impossible. anyone know of a way? or a program already?

    my lecture teacher hasn't showed up in 2 weeks... so my lab teacher just keeps giving us all the hw and expects us to teach ourselves, but the book is pfft
     
  2. DeathClock

    DeathClock Guest

  3. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
  4. Krakerjak

    Krakerjak Active Member

    Joined:
    Jul 7, 2003
    Messages:
    8,288
    Likes Received:
    0
    Location:
    Edmonton eh
    That's a pretty cool problem

    What the fuck is up with that magic number in the quake3 algorithm?
     
  5. DeathClock

    DeathClock Guest

    I would suggest NOT copying the Q3 algorithm for this project, because I doubt you will be able to explain it if your professor asks.
     
  6. DeathClock

    DeathClock Guest

    Has to do with the way floating point numbers are represented as sign bit, a mantissa, and a significand. That is why it appears to be such a large number anyway.
     
  7. ge0

    ge0 New Member

    Joined:
    Oct 31, 2005
    Messages:
    8,398
    Likes Received:
    0
    Location:
    JERSEY
    isn't it Math.pow(i,2)
    and the 2 means what power the i is raised to?


    its bee awhile since i squared something
     
  8. DeathClock

    DeathClock Guest

    lol

    square root... would be sqrt()
     
  9. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    but if he could explain it his teacher would shower him with praises and gifts
     
  10. philvia

    philvia SUCKIN ON MY TITTIES LIKE YOU WANTIN ME CALLIN ME

    Joined:
    May 3, 2007
    Messages:
    11,619
    Likes Received:
    0
    Location:
    NYC
    thats the one i found earlier.. and i have no idea where to even begin. i do need practice but like i said our teacher hasn't even been there to teach. pffft
    this is a class for CONSTRUCTION MANAGEMENT and is 6 hours but only counts as 2 credits. its a BS class and this is a BS assignment :mad:

    i thought about just submitting math.pow(i,1/2) lol
     
  11. DeathClock

    DeathClock Guest

    You would get no points, because calling pow with a float as the second parameter would fail.

    *edit* nvm, that would work, I keep thinking this is C. You would still fail the assignment though lol.
     
  12. Krakerjak

    Krakerjak Active Member

    Joined:
    Jul 7, 2003
    Messages:
    8,288
    Likes Received:
    0
    Location:
    Edmonton eh
    Can you just not use the sqrt() function?
    but others are ok?

    you could do exp( log(i) / 2 )
    but im guessing the assignment want you to do it without using the math library
     
  13. philvia

    philvia SUCKIN ON MY TITTIES LIKE YOU WANTIN ME CALLIN ME

    Joined:
    May 3, 2007
    Messages:
    11,619
    Likes Received:
    0
    Location:
    NYC
    yea we're supposed to be following an algorithm like in the first post.
     
  14. DeathClock

    DeathClock Guest

    Ill walk you through it later, don't have time now but tomorrow afternoon probably.

    Basically, the first thing I look for is a potential loop, you should be able to find it in the algorithm described in the link I gave.
     
  15. philvia

    philvia SUCKIN ON MY TITTIES LIKE YOU WANTIN ME CALLIN ME

    Joined:
    May 3, 2007
    Messages:
    11,619
    Likes Received:
    0
    Location:
    NYC
    no one submitted the homework lol. our teacher gave us this algorithm and we did it in class...

    If A > 0 is a guess of the square root of the positive number Q, then a better approximation to √Q is given by
    B = (A + Q/A)/2.
    Now you use B as an approximation and compute C = (B + Q/B)/2, and so on to get as close as you want to the value of √Q.

    which is MUCH easier than the long division one
     
  16. DeathClock

    DeathClock Guest

    Now, see if you can relate that to the D3 algorithm... because it is exactly the same using a clever initial guess.
     
  17. Limp_Brisket

    Limp_Brisket New Member

    Joined:
    Jan 2, 2006
    Messages:
    48,422
    Likes Received:
    0
    Location:
    Utah
    that's newton's approximation of roots. a.k.a the method i posted in the second post :mamoru:

    carmack's magic number is the guess and then it does one or two more iterations. (the second is commented out in the q3 code)
     

Share This Page