QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: reluer on March 28, 2019, 05:06:13 am

Title: cos(90) problem
Post 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?
Quote
const pi = 3.1415
print cos(90*pi/180)
Title: Re: cos(90) problem
Post by: Qwerkey on March 28, 2019, 05:52:59 am
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?
Title: Re: cos(90) problem
Post by: FellippeHeitor on March 28, 2019, 06:12:32 am
Try:

Code: QB64: [Select]
  1. 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.
Title: Re: cos(90) problem
Post by: bplus on March 28, 2019, 10:01:04 am
Print Using eliminates the exponent notation:
Code: QB64: [Select]
  1. 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])
Title: Re: cos(90) problem
Post by: SMcNeill on March 28, 2019, 10:09:31 am
Print Using eliminates the exponent notation:
Code: QB64: [Select]
  1. 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.  ;)
Title: Re: cos(90) problem
Post by: bplus on March 28, 2019, 10:26:43 am
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!
Title: Re: cos(90) problem
Post by: Pete on March 28, 2019, 11:57:03 am
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
Title: Re: cos(90) problem
Post by: FellippeHeitor on March 28, 2019, 12:01:39 pm
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 ]  
Title: Re: cos(90) problem
Post by: Qwerkey on March 28, 2019, 12:10:16 pm
QB64 is just fine.

Yes, it is, of course.  COS(pi/2) = 0, SIN(pi/2) = 1 (angle in radians)
Title: Re: cos(90) problem
Post by: Pete on March 28, 2019, 12:59:32 pm
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