diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-22 15:11:38 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-22 15:21:14 +0000 |
| commit | 64622b737f070b377fdef3fb31a67c084457bd7b (patch) | |
| tree | 8111bfcf325ed9162dac645a0c68536bad954820 /doc/language/function/cpsc-function-int.7.md | |
| parent | f14b50d776ec743bd62fda22a9c154bba9588840 (diff) | |
feat(codegen)!: require explicit REAL to INTEGER conversion and add INT
Implicit REAL to INTEGER is now a compile error with an INT(...) hint.
INT is a compiler builtin that truncates toward zero and raises a runtime
error for NaN or values outside the INTEGER range.
No existing test program relied on the implicit conversion.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Diffstat (limited to 'doc/language/function/cpsc-function-int.7.md')
| -rw-r--r-- | doc/language/function/cpsc-function-int.7.md | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/doc/language/function/cpsc-function-int.7.md b/doc/language/function/cpsc-function-int.7.md new file mode 100644 index 0000000..245ae70 --- /dev/null +++ b/doc/language/function/cpsc-function-int.7.md @@ -0,0 +1,32 @@ +% CPSC-FUNCTION-INT(7) + +# NAME + +cpsc-function-int - take the integer part of a number + +# SYNOPSIS + +```text +INT(value : REAL) RETURNS INTEGER +INT(value : INTEGER) RETURNS INTEGER +``` + +# DESCRIPTION + +Built into the compiler, so it also works with `-no-std`. + +Return the integer part of a REAL, truncating toward zero: `INT(27.5415)` is 27 and `INT(-27.9)` is -27. An INTEGER argument is returned unchanged. A NaN or a value outside the INTEGER range stops the program with a runtime error. + +REAL never converts to INTEGER implicitly, so assignments, FOR bounds, array bounds and indices, arguments and RETURN values of type REAL are compile errors; wrap them in INT. + +# EXAMPLE + +```text +DECLARE Whole : INTEGER +Whole <- INT(27.5415) +OUTPUT Whole +``` + +# SEE ALSO + +[cpsc-language-overview(7)](../cpsc-language-overview.7.md), [cpsc-keyword-div(7)](../keyword/cpsc-keyword-div.7.md). |
