QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: reluer on March 28, 2019, 05:06:13 am
-
I tried simple trigonometry in QB but it works fine for any value except 90 degree, what's the problem or I shouldn't use 90 degree in cos in QB?
const pi = 3.1415
print cos(90*pi/180)
-
It works perfectly for me (as we'd expect). The answer is close to zero and the displayed result is given in exponentiation format. Would that be what your problem is?
-
Try:
PRINT COS(_D2R(90)) 'as _D2R will convert degrees to radians
If the result is the same you're getting with print cos(90*_pi/180) then all's good. If not, then we have a bug.
-
Print Using eliminates the exponent notation:
PPRINT
using "##.0000";
COS(_D2R(90)) 'as _D2R will convert degrees to radians
Oh hey, "using", is not getting CAPITALIZED in the IDE. (vers 1.2 revision [dev build])
-
Print Using eliminates the exponent notation:
PPRINT
using "##.0000";
COS(_D2R(90)) 'as _D2R will convert degrees to radians
Oh hey, "using", is not getting CAPITALIZED in the IDE. (vers 1.2 revision [dev build])
Fix the syntax so it's not PPRINT and it will. That extra P tosses an error in the IDE for you to correct first. ;)
-
Ha! never noticed the extra P, dang, it printed the correct result "0.0000" so I thought that was what it processed.
I must not have stepped off the line... when I ran it.
Where the extra P came from...? old age!
-
I've got that algorithm...
IF prostate > age THEN p > it_should_b
On my calculator, I get: 0.99962423902337534727046678597814 for: cos(90*3.1415/180) Close to one.
3.1415 / 180 = 0.01745277777777777777777777777778
* 90 = 1.57075
COS(1.57075) = 0.99962423902337534727046678597814
QB64 gives: .00004632679 Close to zero.
I'm surprised there is this much discrepancy.
Pete
-
You're clearly missing the radians/degrees difference. Check your calculator's settings, QB64 is just fine.
COS of 1.57075 degrees (graus in Portuguese):
[ This attachment cannot be displayed inline in 'Print Page' view ]
COS of 1.57075 radians (radianos in Portuguese):
[ This attachment cannot be displayed inline in 'Print Page' view ]
-
QB64 is just fine.
Yes, it is, of course. COS(pi/2) = 0, SIN(pi/2) = 1 (angle in radians)
-
Wow, too many years out of math class for me. I forgot to set the calculator to radians. Default is Degrees. So RE-CALCULATING...
QB64 gives: .00004632679
.0000463267949 From an online calculator. (Same QB64 result, carried out to two more places.)
4.6326794880048353556705900494196e-5 From computer calculator. (Same QB64 result, carried out to many more places.)
Sorry for the confusion,
Pete