## Square root, Sine, Cosine, and Tangent Are any of these available in normal Quest or are there any libraries for them? I heard that they are...
But... it is in radians and not degrees so it needs to be tweaked... K.V.

I don't remember who posted this. It definitely didn't come from me.

(I'm also not certain that it works.)

``````  <function name="calculateSin" parameters="angle, precision" type="int"><![CDATA[
// If you're trying to work out the horiz/vert components of moving some distance, then
// `distance * calculateSin (angle, distance)` will give an answer accurate to the
// nearest square.
if (precision > 1) {
precision = 1 / (2*precision + 1)
}
result = 0
power = 1
numerator = angle
sign = 1
factorial = 1
while ((numerator / factorial) > 0.000001) {
result = result + (numerator * sign / factorial)
numerator = numerator * angle * angle
factorial = factorial * (power+1) * (power+2)
power = power + 2
sign = 0 - sign
}
return (result)
]]></function>
`````` sin(45)
cos(45)
tan(.3)
can't figure out the square root yet... K.V.

Found this, too:

``````  <function name="degreesToRadians" parameters="degrees" type="double">
x = (ToInt(degrees) * pi)/180
y = x/pi
return (x)
</function>
``````
``````sqrt(4)
//Square root of 4
`````` As entered, my Quest says it does not work... I thought I tried sqrt(4)... !!!
I hate how case sensitive Quest it!!!! OK, I got the calculateSin to work...
But the answer does not make sence... K.V.

I did the same, `Sqrt(4)`, then cursed. (Hehehe.)

I have no clue where I found `calculateSin`.

Did you feed it the angle in radians? (I think I got the code from that thread. I remember the radians VS angle conversation, but not how long ago it was (or what the thread was about).) K.V.

Here's a good post from Jay: I do not understand that in the slightest and trust it as far as I can throw it. Which is, nowhere, as I can't throw computer code. Anything on square root? K.V.

`sqrt(4)` outputs 2.

`sqrt(16)` outputs 4. I used:
msg ("the calculated sine of 45 at a distance of 10 spaces is " + calculateSin (45, 10, 1))
and got:
the calculated sine of 45 at a distance of 10 spaces is 1526351
I'm sure what ever the answer is... it is incorrect...

(No, I did not convert to radians) Well, using sin, cos, and tan with radians works. K.V.

using sin, cos, and tan with radians works

Rock on.

@DL

I think there was talk of space travel, and I was confused at one point as to what measurement you were referring...

("...to what measurement you were referring..." Yeah... That's what happens when I don't end my sentence in a preposition.)

...like MACH 5 or something? I hate how case sensitive Quest it!!!!

Usually it us, but not in this case!

I have added a bit to the page in the docs listing functions to note that these functions do exist (I am not going to give each its own page). Also, if any functionality is missing, you can always try to create that functionality yourself, which can be fun, and maybe you can create better functionality, even if it already exists too. "Re-inventing the wheel" can be a lot of fun and helpful/teaching as well, discovering how to do something yourself, instead of just copy and pasting someone else's code, and sometimes, you might just create a better "wheel" too, hehe. @ Pixie
If it's in the code somewhere, where???
I would like to modify it so that the functions accept input in degrees, which people use, and not convert to radians to use it...
(Still don't understand why anyone would really use radians...)
Yes, I would like 1/2 pi of that apple pie...
Sure, I know how to get there... turn to a heading of pi/2 for 33 yards, then go pi^2 for 23 pi feet, turn pi/8 for 1 mile... K.V.

As far as case sensitivity goes, DL and I must have both had typos or something.

I could have sworn I tried `msg(Sqrt(4))` before `msg(sqrt(4))`, with the former throwing an error and the latter outputting 2, but:

``````msg("a = Sqrt(4)")
a = Sqrt(4)
msg("msg(a)")
msg(a)
msg("b = sqrt(4)")
b = sqrt(4)
msg("msg(b)")
msg(b)
msg("msg(Sqrt(4))")
msg(Sqrt(4))
msg("msg(sqrt(4))")
msg(sqrt(4))
``````  DL, they are hard-coded so you cannot see them or override them. You would need to create a new function with a new name (eg "Sine", "Cosine" and "Tangent"). For Sine, the code would be:

``````return (Sin(angle * pi / 180))
``````

Radians are used because they are more fundamental. The 360 degrees in a circle is an arbitrary number made up by the Babylonians, whilst aliens from another star will use radians (by whatever name). If you use these functions in calculus then you have to use radians. Neither of these reasons may be compelling for you...

What would made sense is to have two functions, one for degrees and one for radians, but the designers of .NET decided otherwise, and their use in Quest is so obscure I have no plans to add them myself. K.V.

I was playing with `Cos()`, and I had to use `round()` to get it to display 0 when the angle was 90°. Otherwise, I got 6.12303176911189E-17, which might as well be 0, right?

Times like this, I wish I'd have gone back to school after the eleventh grade! That is the problem with floating point arithmetic. It is accurate to 1 part in 10^16, which is pretty damn good, but the errors canappear.

Be careful using round, as Cos ranges from -1 to 1, so if you round to a whole number, you will only get -1, 0 and 1.

But you should not need to round when actually using it. For the space flight mentioned earlier, if you calculate the change in position along one axis, it is good enough. K.V.

But you should not need to round when actually using it.

Ah. Those are the magic words! I have an Atari 800, with Basic and had the option of setting the computer in:
(It was a command I could use at the start of the program...)

Gradians would be like a metric version of degrees.
Instead of 360 degrees in a circle, there would be 400.

True, if the aliens used "degrees" it would be based on their own planet and star system.
We have degrees because that is the amount the night sky moves per night...
I know, 360 in a circle, but 365 days in a year...
Some time, in human history, after determining the degrees in a circle and days in a year, something happened to the Earth resulting in a slowing of the spin, and/or a change in the distance to the Sun...
Which added 5 days to the year, otherwise, a circle would have 365 degrees...
(FYI... A Marsan circle has 669 degrees...) I have an Atari 800, with Basic and had the option of setting the computer in: Radians, Degrees, or Gradians...

Now you mention it, I have used a version of BASIC that does that long ago. Given BASIC has developed into Visual BASIC on .NET, kind of odd it lost that along the way.

Some time, in human history, after determining the degrees in a circle and days in a year, something happened to the Earth resulting in a slowing of the spin, and/or a change in the distance to the Sun...

More likely they mis-calculated, assuming it must be a nice, neat number, given the world was created byt the gods. What god creates a world where there are 365.2422 days in a year? math (and physics) geek gods (now, I know where 'geek' comes from... 'g(r)eek' gods, lolololol) ... GRRR!!!! (the more I read into accurate time and date --- I wanted to code in an accurate system, specifically leap year and days in a year, the more complex and confusing it got for me... lol) New docs:

This topic is now closed. Topics are closed after 60 days of inactivity.

Quest
Squiffy
ActiveLit

Documentation
Blog
GitHub

Forums