From 64622b737f070b377fdef3fb31a67c084457bd7b Mon Sep 17 00:00:00 2001 From: _ov4 Date: Thu, 22 Oct 2026 15:11:38 +0000 Subject: 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 --- doc/language/function/cpsc-function-int.7.md | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 doc/language/function/cpsc-function-int.7.md (limited to 'doc/language/function/cpsc-function-int.7.md') 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). -- cgit v1.3.1-4-g156e