Skip to content
This repository was archived by the owner on Dec 12, 2024. It is now read-only.

feat: big update, Language→Reference #206

Merged
merged 26 commits into from
May 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a241764
chore: Started the big move
novusnota Apr 8, 2024
65fb5d4
chore: Fix internal linkage
novusnota Apr 8, 2024
ee7fe04
chore: Update redirects
novusnota Apr 9, 2024
fcff4bc
feat: Language->Reference, a big update!
novusnota Apr 29, 2024
e6b82ce
Merge branch 'main' into language/reference
novusnota Apr 29, 2024
b4961a7
wip: intermediate commit
novusnota May 11, 2024
4afd8bf
feat: finished api-strings
novusnota May 12, 2024
2e8fa52
feat: finished api-random
novusnota May 12, 2024
6e5aa5e
feat: api-math and couple of more
novusnota May 13, 2024
0362b9d
feat: api-common
novusnota May 14, 2024
5aaaea5
Merge branch 'main' into language/reference
novusnota May 14, 2024
b7fa4d1
feat: api-debug
novusnota May 14, 2024
23c5d77
feat: api-advanced
novusnota May 14, 2024
431fd40
chore: Apply basic suggestions from code review
novusnota May 14, 2024
109ac86
chore: forward fee
novusnota May 14, 2024
3ad336a
chore: couple fixes
novusnota May 15, 2024
21fd8e0
chore: "API Reference" is now called "Core library" for clarity
novusnota May 15, 2024
4e40daf
fix: explain `require()` better
novusnota May 16, 2024
3949cfa
fix: core-math stuff
novusnota May 16, 2024
f81c12f
chore: "more gas-efficient" over "less gas-consuming"
novusnota May 17, 2024
80450f7
chore: correct the bug
novusnota May 17, 2024
68c039b
chore: placed less used functions lower
novusnota May 17, 2024
b9bd0ac
chore: more about the context and emit
novusnota May 17, 2024
92dcd71
chore: almost nothing throws for core-string
novusnota May 17, 2024
92203b0
feat: done!
novusnota May 20, 2024
b1eb045
fix: clarify
novusnota May 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions pages/ref/core-math.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,28 @@ abs(-(-(-42))); // 42
fun log(num: Int, base: Int): Int;
```

Computes and returns the [logarithm](https://en.wikipedia.org/wiki/Logarithm) of a number `num` to the base `base`.
Computes and returns the [logarithm](https://en.wikipedia.org/wiki/Logarithm) of a number `num` to the base `base`. Results are [rounded down](https://en.wikipedia.org/wiki/Rounding#Rounding_down). Passing negative `num` always gives $0$ as the result, while passing negative `base` gives $-1$ when it is close enough to zero and there's enough gas for calculations, otherwise throws an error with [exit code -14](/book/exit-codes): `Out of gas`.

Usage example:
Usage examples:

```tact
log(1000, 10); // 3, as 10^3 is 1000
// ↑ ↑ ↑ ↑
// num base base num

log(1001, 10); // 3
log(999, 10); // 2
log(-1000, 10); // 0, because of the negative num
log(1024, 2); // 10
log(1024, -2); // -1, because of the negative base
```

<Callout>

Note, that if you only need to obtain logarithms to the base $2$, use the [`log2(){:tact}`](#log2) function, as it's less gas-consuming.

</Callout>

## log2

```tact
Expand All @@ -173,6 +185,12 @@ log2(1024); // 10, as 2^10 is 1024
// num base₂ num
```

<Callout>

In order to reduce gas usage, prefer using this function over calling [`log(){:tact}`](#log) when you only need to obtain logarithms to the base $2$.

</Callout>

## pow

```tact
Expand Down Expand Up @@ -200,6 +218,12 @@ contract Example {
}
```

<Callout>

Note, that if you only need to obtain powers of $2$, use the [`pow2(){:tact}`](#pow2) function, as it's less gas-consuming.

</Callout>

<Callout>

List of functions, that only work at compile-time: [API Comptime](/ref/api-comptime).
Expand Down Expand Up @@ -231,6 +255,12 @@ contract Example {
}
```

<Callout>

In order to reduce gas usage, prefer using this function over calling [`pow(){:tact}`](#pow) when you only need to obtain powers of $2$.

</Callout>

<Callout>

List of functions, that only work at compile-time: [API Comptime](/ref/api-comptime).
Expand Down
Loading