Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions Help/markdown/Table_of_Math_Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ NLP++ now features mathematical functions analogous to those provided in C/C++.
| **FUNCTION NAME** | **RETURNS** | **DESCRIPTION** |
| --- | --- | --- |
| [**abs(num_int)**](abs.md) | **INT** | Get the absolute value of a given integer. |
| [**ceiling(num_float)**](ceiling.md) | **INT** | Round a number up to the nearest whole number. Analogous to the ceil function in C/C++. |
| [**factorial(num_int)**](factorial.md) | **INT** | Get the factorial of a non-negative integer. |
| [**floor(num_float)**](floor.md) | **INT** | Round a number down to the nearest whole number. Analogous to the floor function in C/C++. |
| [**log(num_float)**](log.md) | **FLOAT** | Get the natural (base e) logarithm of a number. Analogous to the log function in C/C++. |
| [**logten(num_float)**](logten.md) | **FLOAT** | Get base 10 logarithm of given number. Analogous to log10 function in C/C++. |
| [**mod(num_int1, num_int2)**](mod.md) | **INT** | Get the remainder of dividing one integer by another. |
| [**pow(base_float, exponent_float)**](pow.md) | **FLOAT** | Raise a number to the given power. Analogous to the pow function in C/C++. |
| [**randomint(num_int1, num_int2)**](randomint.md) | **INT** | Get a random integer between two given integers, inclusive. |
| [**round(num_float)**](round.md) | **INT** | Round a number to the nearest whole number, with halfway cases rounding away from zero. Analogous to the round function in C/C++. |
| [**sqrt(num_float)**](sqrt.md) | **FLOAT** | Get the square root of a number. Analogous to the sqrt function in C/C++. |
| [**truncate(num_float)**](truncate.md) | **INT** | Discard the fractional part of a number, rounding toward zero. Analogous to the trunc function in C/C++. |
| | | |

## See Also
51 changes: 51 additions & 0 deletions Help/markdown/ceiling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[← Help Contents](index.md) | [📘 NLP++ Textbook](NLP++_Textbook.md)

# ceiling

## Purpose

Round a number up to the nearest whole number.

## Syntax

```
returnedInt = ceiling(numFlt)
```

```
returnedInt - type: int

numFlt - type: float
```

## Returns

The smallest whole number that is greater than or equal to the given number.

## Remarks

Analogous to the ceil function in C/C++. Rounds toward positive infinity, so the ceiling of a negative number moves toward zero: the ceiling of -3.7 is -3.

## Example

```
@CODE

"output.txt" << ceiling(3.2) << "\n";

@@CODE
```

```
Outputs:
```

```
4
```

## See Also

[floor](floor.md), [ceiling](ceiling.md), [round](round.md), [truncate](truncate.md)

[Math Functions](Table_of_Math_Functions.md)
51 changes: 51 additions & 0 deletions Help/markdown/floor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[← Help Contents](index.md) | [📘 NLP++ Textbook](NLP++_Textbook.md)

# floor

## Purpose

Round a number down to the nearest whole number.

## Syntax

```
returnedInt = floor(numFlt)
```

```
returnedInt - type: int

numFlt - type: float
```

## Returns

The largest whole number that is less than or equal to the given number.

## Remarks

Analogous to the floor function in C/C++. Rounds toward negative infinity, so the floor of a negative number moves away from zero: the floor of -3.7 is -4. Use [truncate](truncate.md) to discard the fraction and round toward zero instead.

## Example

```
@CODE

"output.txt" << floor(3.7) << "\n";

@@CODE
```

```
Outputs:
```

```
3
```

## See Also

[floor](floor.md), [ceiling](ceiling.md), [round](round.md), [truncate](truncate.md)

[Math Functions](Table_of_Math_Functions.md)
7 changes: 7 additions & 0 deletions Help/markdown/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,17 @@ to a topic.
- **Math Functions**
- [Table of Math Functions](Table_of_Math_Functions.md)
- [abs](abs.md)
- [ceiling](ceiling.md)
- [factorial](factorial.md)
- [floor](floor.md)
- [log](log.md)
- [logten](logten.md)
- [mod](mod.md)
- [pow](pow.md)
- [randomint](randomint.md)
- [round](round.md)
- [sqrt](sqrt.md)
- [truncate](truncate.md)
- [Parse Tree Functions](Table_of_Parse_Tree_Functions.md)
- [Table of Parse Tree Functions](Table_of_Parse_Tree_Functions.md)
- [arraylength](arraylength.md)
Expand Down
51 changes: 51 additions & 0 deletions Help/markdown/log.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[← Help Contents](index.md) | [📘 NLP++ Textbook](NLP++_Textbook.md)

# log

## Purpose

Compute the natural (base e) logarithm of a number.

## Syntax

```
returnedFlt = log(numFlt)
```

```
returnedFlt - type: float

numFlt - type: float
```

## Returns

The natural logarithm of the given number.

## Remarks

Analogous to the log function in C/C++. The argument must be positive. See [logten](logten.md) for the base 10 logarithm.

## Example

```
@CODE

"output.txt" << log(2.718282) << "\n";

@@CODE
```

```
Outputs:
```

```
1
```

## See Also

[sqrt](sqrt.md), [pow](pow.md), [log](log.md), [logten](logten.md)

[Math Functions](Table_of_Math_Functions.md)
53 changes: 53 additions & 0 deletions Help/markdown/pow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[← Help Contents](index.md) | [📘 NLP++ Textbook](NLP++_Textbook.md)

# pow

## Purpose

Raise a number to the given power.

## Syntax

```
returnedFlt = pow(baseFlt,exponentFlt)
```

```
returnedFlt - type: float

baseFlt - type: float

exponentFlt - type: float
```

## Returns

The base raised to the power of the exponent.

## Remarks

Analogous to the pow function in C/C++. A negative base with a fractional exponent is undefined, and a result outside the range of a float is an error.

## Example

```
@CODE

"output.txt" << pow(2,10) << "\n";

@@CODE
```

```
Outputs:
```

```
1024
```

## See Also

[sqrt](sqrt.md), [pow](pow.md), [log](log.md), [logten](logten.md)

[Math Functions](Table_of_Math_Functions.md)
51 changes: 51 additions & 0 deletions Help/markdown/round.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[← Help Contents](index.md) | [📘 NLP++ Textbook](NLP++_Textbook.md)

# round

## Purpose

Round a number to the nearest whole number.

## Syntax

```
returnedInt = round(numFlt)
```

```
returnedInt - type: int

numFlt - type: float
```

## Returns

The whole number nearest the given number.

## Remarks

Analogous to the round function in C/C++. Halfway cases round away from zero, so round of 3.5 is 4 and round of -3.5 is -4.

## Example

```
@CODE

"output.txt" << round(3.5) << "\n";

@@CODE
```

```
Outputs:
```

```
4
```

## See Also

[floor](floor.md), [ceiling](ceiling.md), [round](round.md), [truncate](truncate.md)

[Math Functions](Table_of_Math_Functions.md)
51 changes: 51 additions & 0 deletions Help/markdown/sqrt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[← Help Contents](index.md) | [📘 NLP++ Textbook](NLP++_Textbook.md)

# sqrt

## Purpose

Compute the square root of a number.

## Syntax

```
returnedFlt = sqrt(numFlt)
```

```
returnedFlt - type: float

numFlt - type: float
```

## Returns

The square root of the given number.

## Remarks

Analogous to the sqrt function in C/C++. A negative argument is an error and no value is returned.

## Example

```
@CODE

"output.txt" << sqrt(16) << "\n";

@@CODE
```

```
Outputs:
```

```
4
```

## See Also

[sqrt](sqrt.md), [pow](pow.md), [log](log.md), [logten](logten.md)

[Math Functions](Table_of_Math_Functions.md)
Loading
Loading