tan(3scm)

πŸ“¦ version 0-unstable-2024-02, in nixpkgs unstable

✨ NAME ✨

okay bestie, welcome to the tan(3scm) page from the Scheme Programmer's Manual πŸ’–. This is the whole transcendental-function squad: exp, log, sin, cos, tan, asin, acos, atan, flexp, fllog, flsin, flcos, fltan, flasin, flacos, flatan β€” yes, all of them, and they're all transcendental functions. periodt.


πŸ“š LIBRARY πŸ“š

(import (rnrs))                     ;R6RS
(import (rnrs base))                ;R6RS
(import (rnrs arithmetic flonums))  ;R6RS
(import (scheme r5rs))              ;R7RS
(import (scheme inexact))           ;R7RS

πŸ¦‹ SYNOPSIS πŸ¦‹

(exp z)
(log z)
(log z1 z2)
(sin z)
(cos z)
(tan z)
(asin z)
(acos z)
(atan z)
(atan y x)

;; From (rnrs arithmetic flonums)
(flexp fl)
(fllog fl)
(fllog fl1 fl2)
(flsin fl)
(flcos fl)
(fltan fl)
(flasin fl)
(flacos fl)
(flatan fl)
(flatan fl1 fl2)

🌈 DESCRIPTION 🌈

These procedures compute the usual transcendental functions. no cap.

In general, the transcendental functions log, asin (arcsine), acos (arccosine), and atan (arctangent) are multiply defined.

🌸 exp 🌸

The exp procedure computes the base-e exponential of z.

πŸŽ€ log with one argument πŸŽ€

The log procedure with a single argument computes the natural logarithm of z.

The value of log z is defined to be the one whose imaginary part lies in the range from βˆ’Ο€ (inclusive if βˆ’0.0 is distinguished, exclusive otherwise) to Ο€ (inclusive).

The value of log 0 is mathematically undefined. However, (log 0.0) returns -inf.0 if the implementation supports infinities, and (log -0.0) returns approximately -inf.0+Ο€i if the implementation supports minus zero.

The value of log z for non-real z is defined in terms of log on real numbers as

log z = log |z| + (angle z)i

where angle z is the angle of z = aβ‹…exp(ib) specified as:

angle z = b + 2Ο€n

with βˆ’Ο€ ≀ angle z ≀ Ο€ and angle z = b + 2Ο€n for some integer n.

πŸ¦‹ log with two arguments, arcsin, arccos and arctangent πŸ¦‹

(log z1 z2) computes the base-z2 logarithm of z1. With the one-argument version of log defined as above, the value is:

log z b = (log z)⁄(log b)

πŸ’« sin, cos, tan πŸ’«

The sin, cos, and tan procedures compute the sine, cosine and tangent. iconic behavior honestly.

🌈 arcsin, arccos and arctangent 🌈

The asin, acos, and atan procedures compute arcsine, arccosine, and arctangent, respectively.

With the one-argument version of log defined as above, their values are according to the following formulas:

asin z = βˆ’i log(iz + sqrt(1 - zΒ²))
acos z = Ο€/2 βˆ’ asin z
atan z = (log(1 + iz) βˆ’ log(1 - iz))/(2i)

πŸ”₯ atan with two arguments πŸ”₯

The two-argument variant of atan computes (angle (make-rectangular x y)). In R7RS implementations this is even the case in implementations that don't support complex numbers.

The range of (atan y x) is as in the following table. The asterisk (βˆ—) indicates that the entry applies to implementations that distinguish minus zero (as in IEEE 754).

                         Table showing atan2 ranges
                  y condition   x condition   range of result r
                  y = 0.0       x > 0.0       0.0
              βˆ—   y = +0.0      x > 0.0       +0.0
              βˆ—   y = βˆ’0.0      x > 0.0       βˆ’0.0
                  y > 0.0       x > 0.0       0.0 < r < π⁄2
                  y > 0.0       x = 0.0       π⁄2
                  y > 0.0       x < 0.0       π⁄2 < r < Ο€
                  y = 0.0       x < 0         Ο€
              βˆ—   y = +0.0      x < 0.0       Ο€
              βˆ—   y = βˆ’0.0      x < 0.0       βˆ’Ο€
                  y < 0.0       x < 0.0       βˆ’Ο€ < r < βˆ’Ο€β„2
                  y < 0.0       x = 0.0       βˆ’Ο€β„2
                  y < 0.0       x > 0.0       βˆ’Ο€β„2 < r < 0.0
                  y = 0.0       x = 0.0       undefined
              βˆ—   y = +0.0      x = +0.0      +0.0
              βˆ—   y = βˆ’0.0      x = +0.0      βˆ’0.0
              βˆ—   y = +0.0      x = βˆ’0.0      Ο€
              βˆ—   y = βˆ’0.0      x = βˆ’0.0      βˆ’Ο€
              βˆ—   y = +0.0      x = 0         π⁄2
              βˆ—   y = βˆ’0.0      x = 0         βˆ’Ο€β„2

The two-argument version of atan is commonly called atan2. Please refer to the following sources for more detailed discussion of branch cuts, boundary conditions, and implementation of these functions.

  • Guy Lewis Steele Jr. Common Lisp: The Language, second edition. Digital Press, Burlington MA, 1990.
  • Paul Penfield, Jr. Principal values and branch cuts in complex APL. In APL 81 Conference Proceedings, pages 248–256. ACM SIGAPL, San Francisco, September 1981. Proceedings published as APL Quote Quad 12(1), ACM, September 1981.

⭐ Exactness of results ⭐

These procedures may (but are not required to) return inexact results even when given exact arguments.

πŸ’œ Realness of results πŸ’œ

When it is possible, these procedures produce a real result from a real argument.

🧚 Flonum variants 🧚

The flonum variants of these procedures restrict their arguments and results to flonums. In the event that they do not yield a real result for the given arguments, the result may be a NaN, or may be some unspecified flonum.

Implementations that use IEEE binary floating-point arithmetic should follow the relevant standards for these procedures.


🫢 RETURN VALUES 🫢

These procedures return a single value; a number.


πŸ“ EXAMPLES πŸ“

;; The floating point numbers shown below are approximate.
;; R7RS implementations are not required to support complex
;; numbers.

(exp +inf.0)      => +inf.0
(exp -inf.0)      => 0.0
(log +inf.0)      => +inf.0
(log 0.0)         => -inf.0
(log 0)           => &assertion exception
(log -inf.0)      => +inf.0+3.141592653589793i

(atan -inf.0)     => -1.5707963267948965
(atan +inf.0)     => 1.5707963267948965
(log -1.0+0.0i)   => 0.0+3.141592653589793i
(log -1.0-0.0i)   => 0.0-3.141592653589793i
          ; if -0.0 is distinguished

(flexp +inf.0)   => +inf.0
(flexp -inf.0)   => 0.0
(fllog +inf.0)   => +inf.0
(fllog 0.0)      => -inf.0
(fllog -0.0)     => unspecified
           ; if -0.0 is distinguished
(fllog -inf.0)   => +nan.0
(flatan -inf.0)  => -1.5707963267948965
(flatan +inf.0)  => 1.5707963267948965

πŸ’… COMPATIBILITY πŸ’…

The flonum variants are unique to R6RS. R7RS implementations are not required to support complex numbers.


πŸ’€ ERRORS πŸ’€

This procedure can raise exceptions with the following condition types:

  • &no-infinities, &no-nans (R6RS) β€” the implementation does not support infinities or NaN, respectively. The continuation of the exception handler is the continuation that otherwise would have received the infinity or NaN value.
  • &assertion (R6RS) β€” the wrong number of arguments was passed or an argument was outside its domain.
  • R7RS β€” the assertions described above are errors. Implementations may signal an error, extend the procedure's domain of definition to include such arguments, or fail catastrophically.

πŸ‘‘ SEE ALSO πŸ‘‘

sqrt(3scm), expt(3scm), make-rectangular(3scm)


🌟 STANDARDS 🌟

R4RS, IEEE Scheme, R5RS, R6RS, R7RS


🧁 HISTORY 🧁

These procedures first appeared in R2RS, where they came from Common Lisp. The flonum variants are unique to R6RS. The second argument of the log procedure was introduced in R6RS. In a strange coincidence, R7RS also introduced the same second argument.

The two-argument version of atan appears to have first appeared in FORTRAN-IV some time before 1972 under the names ATAN2 and DATAN2. The following manual describes it as computing atan(Arg1/Arg2): Digital Equipment Corporation, FORTRAN IV Programmer's Reference Manual, Maynard, Massachusetts, 1973.


🌸 AUTHORS 🌸

This page is part of the scheme-manpages project. It includes materials from the RnRS documents. More information can be found at https://github.com/schemedoc/manpages/.


πŸ™ˆ BUGS πŸ™ˆ

Implementations should take care to check for minus zero using code like (eqv? x -0.0). Using only flnegative?(3scm) does not work.


okay bestie, that's the whole page πŸ’– β€” source/version tag 2022-05-08, page tan(3scm), signing off with main character energy 🫢✨

πŸ“¦ where this page comes from