17

Most programming languages that feature mathematical functions expect the arguments to be in radians. For example, sin(1) would typically return 0.841471, equivalent to sin 57.295°. But a couple of older languages didn't follow this convention:

  • Logo (1967): sin 1 returns “You don't say what to do with 0.0174524058”
  • PostScript (1982): 1 sin leaves the value of 0.0174524058 on the stack

Are there others that work directly specifying only degrees?

(For greater clarity: OpenSCAD (2010) specifies degrees, but is still in active development. Berkeley Logo also added functions such as radsin to allow use of radians. The HP-35 calculator only worked in degrees, but is not a programming language.)

1

5 Answers 5

9

The Atari BASIC (c) 1978, 1979, 1983 that came with the Atari 600 XL homecomputer had the DEG and RAD statements that not only decided upon the unit on input to SIN and COS, but also the unit on output from ATN.
Internally to BASIC, the use of Polynomial Evaluation meant degrees could stay degrees, and radians could stay radians. eg. For SIN and COS, they first divide the input by 90 (DEG) or pi/2 (RAD). Then they use the quotient mod 4 to establish the quadrant which will enable them to adjust the sine that they calculate using Polynomial Evaluation. All of this uses assembly everywhere which undoubtedly is fastest.
Had the DEG statement not been available, the user that would have preferred working from degrees, would have had to use costly multiplications by pi/180 or 180/pi to convert into or out-of radians. This would have been important in the space-cramped 6502 environment.

In my school we did learn about radians, but we exclusively used degrees. I was very happy that once I had bought the Atari 600 XL, I could just issue a one-time DEG statement and keep working in the comfort of degrees instead of having to use radians.

My next Atari computer was the 1040ST with the 68000 CPU inside. It came with the Atari ST BASIC (c) 1987. The DEG and RAD statements had gone. Just like any other programming language that I've seen from then on it exclusively worked with radians for its COS, SIN, TAN, and ATN functions.

5
  • Out of curiosity, does sin(1800) when in degrees mode? How about sin(31.4159265359) when in radians mode?
    – supercat
    Jun 21, 2023 at 21:59
  • 1
    @supercat I guess that would not have been a problem. From the source code I just glimpsed, I see the first operation they do is dividing the input by 90 (DEG) or pi/2 (RAD). They then use the quotient mod 4 to establish the quadrant which enables them to adjust the SIN that they calculate.
    – Sep Roland
    Jun 21, 2023 at 22:20
  • When using degrees, is the input ever converted to radians, or does it simply work with the quarter-circle units that resulted from that first division you mentioned?
    – supercat
    Jun 22, 2023 at 5:55
  • 1
    @supercat The sine is computed as a polynomial in quarter circle units. Since this polynomial is close to sin(pi/2 x), pi makes an appearance of sorts in the coefficients.
    – WimC
    Jun 23, 2023 at 18:11
  • @supercat Degrees are not really converted to radians. Like WimC wrote above, they use Polynomial Evaluation.
    – Sep Roland
    Jun 24, 2023 at 13:44
7

BASIC-G v2.0 for the PMD 85-2 contains commands DEG and RAD that switch the mode between radians (the default) and degrees for the functions SIN, COS and TANG. This was a new feature of the v2.0 over the previous BASIC-G v1.0 for the PMD 85-1.

2
  • 1
    so if you wrote a programme in BASIC-G 2.0 assuming radians, but then added a line at the top calling DEG, it would give wrong results?
    – scruss
    Jun 20, 2023 at 18:02
  • 1
    @scruss Exactly. Using stateful commands is fun, especially in combination with GOSUBs and similar, when you cannot guarantee the program executed the switch or not (thus putting DEG at the very first line is actually the best option) Jun 20, 2023 at 19:21
6

Several BASIC dialects have the option to set the input unit for trigonometric functions. Sharp Pocket Computer BASIC have 2 means to set the input. Either by the setting button DEG/RAD/GRAD or by the BASIC keywords DEGREE, RADIAN and GRAD. On CASIO pocket computer a similar system exists. Either a settings button or the MODE keyword with option (4/5/6 for the FX-702P p.ex.).

1
  • but they still have the capability of working in radians, which PostScript and pre-UCB Logo do not
    – scruss
    Jun 20, 2023 at 18:03
5

Garry Kitchen's Gamemaker supported specifying a sprite movement direction as a value between 0 and 255; presumably this then used a lookup table for the cos/sin (dx/dy) values, possibly with some smarts to exploit symmetry etc. to make the table smaller, the point being this is one example where the language used neither degrees nor radians for trig-like things as was noted in a now-deleted comment.

5
  • 1
    The trig libraries in Super Mario 64, and countless other games as well, use the same units. While scenarios where radians are the best scaling factor may be more common than those where degrees or grads are the best, units of whole resolutions are for many applications better yet.
    – supercat
    Jun 20, 2023 at 16:15
  • 2
    These are brads, not degrees
    – scruss
    Jun 20, 2023 at 18:04
  • @scruss: The question could sensibly be viewed more broadly as "anything other than [bleep]ing radians", which are an inferior choice for most actions which involve geometry, bordering on pants-on-head stupid for things like HTML5 canvas "rotate" (which is incapable of rotating the graphics transform by exactly 1/4 turn).
    – supercat
    Jun 21, 2023 at 14:57
  • @supercat - but broadly dilutes the point. It's strange that HTML5 didn't inherit PostScript's use of degrees. Math.PI / 2 is as close to a 1/4 turn as a canvas ever needs. All methods of angular representation have limits: my design work sometimes requires angles of 1/7 and 1/14 of a turn and none of degrees, radians, grads, brads or floating-point turns can represent them exactly
    – scruss
    Jun 21, 2023 at 20:35
  • 1
    @scruss: At least when I tested it in Firefox some years back, an algorithm that repeatedly performed rotations by Math.PI/2 would start producing "horizontal" and "vertical" lines which weren't precisely horizontal and vertical. A rotation by 90 degrees should yield a transform of precisely [0,1,-1,0,0,0] or [0,-1,1,0,0,0], depending upon direction, but a rotation by Math.PI/2 can't.
    – supercat
    Jun 21, 2023 at 20:48
-2

This is a library feature: not a language feature. None of the mainstream languages have built in trigonometry. Some of the libraries just add a d to the end of the function name.

For instance, GNU Fortran, Intel Fortran and Matlab libraries have sind, cosd, tand and atan2d.

3
  • 14
    In some of the languages the OP mentioned in the question it is in fact a language feature, not a library feature, as the distinction between language and library is frequently not made in earlier languages. In both Logo and Postscript, for example, the sin function shown by the OP is built-in to the language, not considered part of a library or framework like we talk about them now.
    – davidbak
    Jun 20, 2023 at 4:06
  • 3
    Interestingly, the Algol 60 Revised Report merely says there should be a function sin(E) but does not explicitly specify the units of the argument E :-) Unless one is supposed to infer radians from the wording 'the standard functions of analysis'.
    – dave
    Jun 20, 2023 at 11:17
  • 1
    even then, Fortran has always had built-in trig functions as part of the language
    – scruss
    Jun 20, 2023 at 18:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .