Author Topic: cos(90) problem  (Read 3019 times)

0 Members and 1 Guest are viewing this topic.

Offline reluer

  • Newbie
  • Posts: 1
    • View Profile
cos(90) problem
« 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)

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: cos(90) problem
« Reply #1 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?

FellippeHeitor

  • Guest
Re: cos(90) problem
« Reply #2 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.
« Last Edit: March 28, 2019, 07:09:52 am by FellippeHeitor »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: cos(90) problem
« Reply #3 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])

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: cos(90) problem
« Reply #4 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.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: cos(90) problem
« Reply #5 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!

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: cos(90) problem
« Reply #6 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/

FellippeHeitor

  • Guest
Re: cos(90) problem
« Reply #7 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):
  [ You are not allowed to view this attachment ]  

COS of 1.57075 radians (radianos in Portuguese):
  [ You are not allowed to view this attachment ]  
« Last Edit: March 28, 2019, 12:05:25 pm by FellippeHeitor »

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: cos(90) problem
« Reply #8 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)

Offline Pete

  • Forum Resident
  • Posts: 2361
  • Cuz I sez so, varmint!
    • View Profile
Re: cos(90) problem
« Reply #9 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
Want to learn how to write code on cave walls? https://www.tapatalk.com/groups/qbasic/qbasic-f1/