Gauche Devlog

< Pretty print indentation | Pipeworks >


Real numerical functions

Scheme devines a set of elementary functions that can handle complex numbers. In Gauche, complex elementary functions is built on top of real domain functions. Up to 0.9.12, we had real-only version with the name such as %sin or %exp. As the percent prefix suggests, they are not meant to be used directly; sin ro exp are built on top of them.

However, sometimes you want to use real-only versions to avoid overhead of type testing and dispatching complex numbers. srfi:94 defines real-domain functions, so we decided to adapt them. Now you have real-sin, real-exp etc. (draft:real-exp) as built-in.

Note that scheme.flonum also provides "flonum-only" version of elementary functions, e.g. flsin (ref:scheme.flonum). They won't even accept exact numbers. Since it is in R7RS-large, you may want to use them for portable code.

Although the names %sin etc. are undocumented and not meant to be directly used, they were visible by default, so some existing code are relying on it. It needs some effort to rewrite all occurrences of such functions with the new real-sin etc, so we provide a compatibility module, compat.real-elementary-functions. Just using it in your code provides compatibility names. If you want to make your code work on both 0.9.12 and 0.9.13, you can use cond-expand:

  ((library compat.real-elementary-functions)
   (use compat.real-elementary-functions))

Tags: 0.9.13, NumericFunctions