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.

DarkBASIC Discussion / Maths questions

Author
Message
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 26th Feb 2008 20:19 Edited at: 25th Apr 2008 21:03
Hey guys!

Can someone fill out the following:

addition : +
Subtraction : -
Multiplication : *
Division : /
Squared : ?
Cubed : ?
Square route : ?
Cube route : ?
Pi : ?

What does it mean, when there is a "!" in a formula?

ex: (5/3)!2 (or something like that...)

Thanks in advance, TheComet

Oooooops!!! I accidentally formated drive c.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 26th Feb 2008 20:26 Edited at: 26th Feb 2008 20:35
Squared: Num^2

Cubed: Num^3

Square route: Sqrt(Num)

Cube route: Doesn't exist

Pi: 3.142

Quote: "What does it mean, when there is a "!" in a formula?"


Probably NOT - which you don't have in DBC.

TDK_Man

Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 26th Feb 2008 20:26 Edited at: 26th Feb 2008 20:28
Squared: n^2 (n^x = n to the power of x)
Cubed: n^3
Square Route: Sqrt(n)

[edit]
Doh! Damn you TDK!
you didn't edit the cubed though

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 26th Feb 2008 20:36
Quote: "you didn't edit the cubed though"


Oops!

Nice to beat someone else to it for a change!...

TDK_Man

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 26th Feb 2008 21:30
For any root of a number you can raise the number to the power of 1.0/root#

so cubed root of 8 = 8^(1.0/3.0) = 2

Quote: "Probably NOT - which you don't have in DBC"

You're right TDK, it is NOT - but I think it works a little differently in DBC than it may in other languages. It's a little more like != .

! is the NOT operator and returns a true or false value (1 or 0) when two values are compared. a!b (read a NOT b) results in 1 if the a and b are different. a!b results in 0 if a and b are the same.



Enjoy your day.
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 26th Feb 2008 22:51
Didn't know there was a "!" in DBC
What's the point in "!" when you can type "<>"?

Thanks for the root example latch, that actually made sense to me

TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 26th Feb 2008 22:59
Quote: "but I think it works a little differently in DBC than it may in other languages"


To be honest I didn't even know it existed in DBC - I've never had a call for it mainly because DBC doesn't have bit-sized variables.

TDK_Man

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 27th Feb 2008 02:18 Edited at: 27th Feb 2008 02:26
Quote: "What's the point in "!" when you can type "<>"?"

It eliminates the need for a conditional test because it's result is the test. It's mostly used for bit operations, but you could probably find other uses like establishing movement and screen limits for a sprite all in one:



or more optimized:



Enjoy your day.
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 27th Feb 2008 16:09 Edited at: 27th Feb 2008 16:13
Quote: "It's mostly used for bit operations"


Here's a quick explanation:

Decimal 12 = Binary 00001100
Decimal 15 = Binary 00001111


So, 12 NOT 15 equates to comparing the 8 bits of the two numbers.

If they are NOT the same it results in a 1 and if they are the same you get a 0.

So, working from left to right in both, the first 4 bits are 0 (the same) which gives you 0000.

The next two bits are 1's in both so being the same again results in two more 0's.

The last two bits of each are 00 and 11 and as they are NOT the same results in 1 for each bit. So the whole operation would be:


00001100
00001111
-----------
00000011


In decimal, 00000011 = 3, so 12 NOT 15 actually equals 3.

In DBC, as Latch says, ! doesn't work correctly - it actually works like <> (not equals) and 12 ! 15 incorrectly returns 1 to say that it doesn't equal, so to be honest there's no point using it in that context.

NOT is not the same as NOT EQUALS.

As well as NOT, you also have...

AND (1 bit on AND the other):


00001100
00001111
-----------
00001100
<< 12 AND 15 = 12

OR (1 bit on OR the other or both):


00001100
00001111
-----------
00001111
<< 12 OR 15 = 15

XOR - Exclusive OR (1 bit on OR the other but not both):


00001100
00001111
-----------
00000011
<< 12 XOR 15 = 3

The operators =, <>, <, >, <= and >= are not the same thing. Neither are the AND and OR used in If..Then statements.

And, if you are wondering what possible use you would have for OR, XOR, AND and NOT, you've just discovered one of the reasons why DB makes life so much easier for you compared to the earlier days when I started programming.

For example, you now have sprites and 'transparency flags' with image commands so you can see the background through black sections.

Years ago, to get an image onto the screen without being surrounded by a black box I had to:

* Create a mask from the image
* Paste the mask onto the screen leaving a 'hole' where the image data should be
* Paste the image on the screen only putting pixels where the hole is.

Comparing the bits of the pixels in the image and the mask to see which were on, which were off and which were both on or off had to be done with OR, XOR, AND and NOT.

TDK_Man

Sinani201
18
Years of Service
User Offline
Joined: 16th Apr 2007
Location: Aperture Science Enrichment Center
Posted: 28th Feb 2008 05:27 Edited at: 28th Feb 2008 05:29
Quote: "Pi: 3.142"

you're rounding it? I know it very far by heart. I know it up to: 3.1415926535897932.
There's a website with PI up to one million digits... I'll post a link
WARNING: That site has PI up to a million digits. IT might take a while to load.

Seriously, how do you make the little blue text come up below your message?
BN2 Productions
21
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 28th Feb 2008 07:02
OK about the !

If you mean in a math formula, then ! means factorial (9!=9*8*7*6*5*4*3*2*1). Otherwise, it means NOT in some computer languages.

Note: you can't take a factorial of a fraction.
TheComet
17
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 28th Feb 2008 08:17
Thanks to everyone!

@TDK

You posted the "christmas game" around christmas, where you have to collect presents in an amount of time. In that code, which I don`t have and can`t find, you used a "!" where you control the camera input.

TheComet

Oooooops!!! I accidentally formated drive c.

Login to post a reply

Server time is: 2025-06-04 01:49:17
Your offset time is: 2025-06-04 01:49:17