Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Square root finder + rounder

Author
Message
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 17th Dec 2007 21:47 Edited at: 17th Dec 2007 21:51
Here's a little time-killer project i made in an hour or two.

This program will take a number and calculate the square root, tell you what my formula got, what my rounder gets, and what the sqrt() function calculates.

>= x.5 rounds to x + 1. Less rounds to x.

Source:


I'll have the download up in a sec...

n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 17th Dec 2007 22:23
Here's the .exe:



NeX the Fairly Fast Ferret
19
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 17th Dec 2007 22:27
Eh, no, that's a smiley.


Since the other one was scaring you guys so much...
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 17th Dec 2007 22:31 Edited at: 17th Dec 2007 22:31
Click it

David R
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: 3.14
Posted: 17th Dec 2007 22:37 Edited at: 17th Dec 2007 22:37
How... pointless The standard library doesn't exist so you can pointlessly reinvent the wheel you know :p


09-f9-11-02-9d-74-e3-5b-d8-41-56-c5-63-56-88-c0
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 17th Dec 2007 22:57 Edited at: 17th Dec 2007 22:58
There's no rounding funtion in the stl .

Besides, I did this because I was bored. Hence "...time killer..."

David R
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: 3.14
Posted: 17th Dec 2007 23:05 Edited at: 17th Dec 2007 23:10
Quote: "There's no rounding funtion in the stl ."


Erm, firstly, I was talking C standard library (not STL)
And secondly, the rounding function is round() (in math.h)

EDIT:
Then again, round() doesn't work in VS. But you can just do floor(x+0.5f)


09-f9-11-02-9d-74-e3-5b-d8-41-56-c5-63-56-88-c0
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 17th Dec 2007 23:07 Edited at: 17th Dec 2007 23:07
No it isn't.

David R
21
Years of Service
User Offline
Joined: 9th Sep 2003
Location: 3.14
Posted: 17th Dec 2007 23:11
Quote: "No it isn't."


Yes it is. I just compiled your code using round() instead of what you've made.


09-f9-11-02-9d-74-e3-5b-d8-41-56-c5-63-56-88-c0
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 17th Dec 2007 23:40


I never knew that! LOL

Oh well, so what? I like doing stuff like this. Kills time.

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 18th Dec 2007 06:26 Edited at: 18th Dec 2007 06:34
OK so it's written in DBC but this is much faster


The secret isn't 0.5, it's that doubling the number will produce a whole number if the decimal is greater or equal to 0.5 (2 * 0.5 = 1).

e.g.
1.45 * 2 = 2.9 = 2 (as integer)
1.45 = 1 (as integer)
(so) 2 - 1 = 1

1.8 * 2 = 3.6 = 3 (as integer)
1.8 = 1 (as integer)
(so) 3 - 1 = 2

n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 18th Dec 2007 22:15
Ok, now write a function that finds the square root. Without using sqrt (If that is a command/function in DB)

spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 19th Dec 2007 17:56
Reminds me of code I wrote back in 2003 to find square and cube roots without using built-in commands;

http://forum.thegamecreators.com/?m=forum_view&t=18952&b=7



Boo!
n008
17
Years of Service
User Offline
Joined: 18th Apr 2007
Location: Chernarus
Posted: 19th Dec 2007 19:59
It should be easy to find square roots in DarkBASIC:




ionstream
20
Years of Service
User Offline
Joined: 4th Jul 2004
Location: Overweb
Posted: 19th Dec 2007 22:18
I like that Babylonian method spooky . Nice and simple, and far more accurate than guess-and-check.

demons breath
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: Surrey, UK
Posted: 20th Dec 2007 22:19
@Spooky: I'm having a little difficulty figuring out how your method worked, actually. Is it just an iteration?

"A West Texas girl, just like me"
-Bush

Login to post a reply

Server time is: 2024-11-19 17:54:31
Your offset time is: 2024-11-19 17:54:31