Author Topic: A clock  (Read 4893 times)

0 Members and 1 Guest are viewing this topic.

Offline Han

  • LV3 Member (Next: 100)
  • ***
  • Posts: 62
  • Rating: +7/-0
    • View Profile
Re: A clock
« Reply #15 on: December 22, 2013, 10:28:03 am »
Changing the user's settings is not a really good programming practice unless you can guarantee that no matter what the user does during program execution, their settings will be returned to the state prior to running the program. In your case, if the user presses the [On] key, program execution is halted and there is a chance the user's angle settings do not get restored. Instead, use the angle setting to test whether or not your own program needs to do angle conversion. If your code is written with the assumption that radians are used, and the user's calculator happens to be in degrees, then

Code: [Select]
GETANGLE(a)
BEGIN
  IF HAngle THEN
    a:=a/PI*180; // angle was assumed to be in radians when programmed; convert to degrees
  END;
  RETURN(a);
END;

So now you can just do SIN(GETANGLE( blah )) and always assume that the angle is in radians (while you program). Whether or not the user's settings is in radians won't affect the outcome as GETANGLE() will convert accordingly.

Offline DJ Omnimaga

  • Now active at https://codewalr.us
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55820
  • Rating: +3151/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • DJ Omnimaga Music
Re: A clock
« Reply #16 on: December 22, 2013, 12:00:25 pm »
Oh nice, I didn't know it was possible to detect in which mode the calc is set. In TI-BASIC, we sometimes have to force mode changes because we absolutely have no other choice.
In case you are wondering where I went, I left Omni back in 2015 to form CodeWalrus due to various reasons explained back then, but I stopped calc dev in 2016 and am now mostly active on the CW Discord server at https://discord.gg/cuZcfcF


Bandcamp|Reverbnation|Facebook|Youtube|Twitter

Offline Han

  • LV3 Member (Next: 100)
  • ***
  • Posts: 62
  • Rating: +7/-0
    • View Profile
Re: A clock
« Reply #17 on: December 25, 2013, 12:32:08 am »
Oh nice, I didn't know it was possible to detect in which mode the calc is set. In TI-BASIC, we sometimes have to force mode changes because we absolutely have no other choice.

Actually, you can create a similar workaround on the TI. In place of HAngle, you can simply test SIN(PI)==0 to determine whether you are in degree mode or radian mode. If the boolean is true, then you are in radian mode. Otherwise, you are in degree mode.

Offline DJ Omnimaga

  • Now active at https://codewalr.us
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55820
  • Rating: +3151/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • DJ Omnimaga Music
Re: A clock
« Reply #18 on: January 08, 2014, 08:40:35 pm »
Oh nice, thanks for the trick. :)
In case you are wondering where I went, I left Omni back in 2015 to form CodeWalrus due to various reasons explained back then, but I stopped calc dev in 2016 and am now mostly active on the CW Discord server at https://discord.gg/cuZcfcF


Bandcamp|Reverbnation|Facebook|Youtube|Twitter