added helper function documentation

Valerie Wolfe 2023-06-15 11:58:47 -04:00
parent 07c45b2f16
commit 7a8baf4df4

67
Helper-Functions.md Normal file

@ -0,0 +1,67 @@
`qm` has a number of common helper functions not included in the `evalexpr` crate:
# Mathematics
## Fix
`fix` can be used to round a float to *n* digits.
| Signature | Description | Output |
| ------------------- | ------------------------- | ------ |
| fix(x: f64, n: i64) | rounds *x* to *n* digits. | f64 |
## Logarithm
`log` can be used to calculate logarithms. Defaults to ln.
| Signature | Description | Output |
| ------------------- | ---------------------------------------- | ------ |
| log(x: num) | calculates the natural logarithm of *x* | f64 |
| log(x: num, n: num) | calculates the base *n* logarithm of *x* | f64 |
## Square Root
`sqrt` is used to calculate square roots.
| Signature | Description | Output |
| ------------ | --------------------------------- | ------ |
| sqrt(n: num) | calculates the square root of *n* | f64 |
| √(n: num) | " | " |
# Data Science
## Average
`avg` is used to calculate averages of an arbitrarily large string of numbers.
| Signature | Description | Output |
| ------------------ | ---------------------------------------------- | ---------- |
| avg(n0: num, ...) | calculates the average of all numbers provided | i64 or f64 |
# Computer Science
## Radix Conversion
`bin`, `hex`, and `oct` can be used to convert numbers to binary, hexadecimal, and octal strings (and the reverse), respectively.
| Signature | Description | Output |
| ----------- | ---------------------------------------------------------------- | ------ |
| bin(n: i64) | converts *n* to a string with its binary representation | str |
| bin(b: str) | converts a binary string *b* to the integer it represents | i64 |
| hex(n: i64) | converts *n* to a string with its hexadecimal representation | str |
| hex(h: str) | converts a hexidecimal string *h* to the integer it represents | i64 |
| oct(n: i64) | converts *n* to a string with its octal representation | str |
| oct(o: str) | converts an octal string *o* to the integer it represents | i64 |
### Binary
Binary strings will be outputted with the prefix `0b`. It will attempt to parse strings without this prefix, and will handle errors gracefully.
### Hexadecimal
Hexadecimal strings will be outputted with the prefix `0x`. It will attempt to parse strings without this prefix, and will handle errors gracefully.
### Octal
Octal strings will be outputted with the prefix `0o`. It will attempt to parse strings without this prefix, and will handle errors gracefully.