このページでは IEC 61131-3 の標準POUを扱います。標準関数群と標準ファンクションブロック群を、適用可能な型、インターフェース、動作仕様、使用例の順に整理します。
標準POUの名前を俯瞰したい場合は、以下の一覧を使用してください。型名フィルタは、POU名に含まれる型接尾辞やオーバーロード名を基準に絞り込みます。
sint_to_int, sint_to_dint, sint_to_lint, sint_to_usint, sint_to_uint, sint_to_udint, sint_to_ulint, sint_to_real, sint_to_lreal, int_to_sint, int_to_dint, int_to_lint, int_to_usint, int_to_uint, int_to_udint, int_to_ulint, int_to_real, int_to_lreal, dint_to_sint, dint_to_int, dint_to_lint, dint_to_usint, dint_to_uint, dint_to_udint, dint_to_ulint, dint_to_real, dint_to_lreal, lint_to_sint, lint_to_int, lint_to_dint, lint_to_usint, lint_to_uint, lint_to_udint, lint_to_ulint, lint_to_real, lint_to_lreal, usint_to_sint, usint_to_int, usint_to_dint, usint_to_lint, usint_to_uint, usint_to_udint, usint_to_ulint, usint_to_real, usint_to_lreal, uint_to_sint, uint_to_int, uint_to_dint, uint_to_lint, uint_to_usint, uint_to_udint, uint_to_ulint, uint_to_real, uint_to_lreal, udint_to_sint, udint_to_int, udint_to_dint, udint_to_lint, udint_to_usint, udint_to_uint, udint_to_ulint, udint_to_real, udint_to_lreal, ulint_to_sint, ulint_to_int, ulint_to_dint, ulint_to_lint, ulint_to_usint, ulint_to_uint, ulint_to_udint, ulint_to_real, ulint_to_lreal
real_to_sint, real_to_int, real_to_dint, real_to_lint, real_to_usint, real_to_uint, real_to_udint, real_to_ulint, real_to_lreal, lreal_to_sint, lreal_to_int, lreal_to_dint, lreal_to_lint, lreal_to_usint, lreal_to_uint, lreal_to_udint, lreal_to_ulint, lreal_to_real
byte_to_word, byte_to_dword, byte_to_lword, word_to_byte, word_to_dword, word_to_lword, dword_to_byte, dword_to_word, dword_to_lword, lword_to_byte, lword_to_word, lword_to_dword
byte_to_sint, byte_to_int, byte_to_dint, byte_to_lint, byte_to_usint, byte_to_uint, byte_to_udint, byte_to_ulint, word_to_sint, word_to_int, word_to_dint, word_to_lint, word_to_usint, word_to_uint, word_to_udint, word_to_ulint, dword_to_sint, dword_to_int, dword_to_dint, dword_to_lint, dword_to_usint, dword_to_uint, dword_to_udint, dword_to_ulint, lword_to_sint, lword_to_int, lword_to_dint, lword_to_lint, lword_to_usint, lword_to_uint, lword_to_udint, lword_to_ulint
sint_to_byte, sint_to_word, sint_to_dword, sint_to_lword, int_to_byte, int_to_word, int_to_dword, int_to_lword, dint_to_byte, dint_to_word, dint_to_dword, dint_to_lword, lint_to_byte, lint_to_word, lint_to_dword, lint_to_lword, usint_to_byte, usint_to_word, usint_to_dword, usint_to_lword, uint_to_byte, uint_to_word, uint_to_dword, uint_to_lword, udint_to_byte, udint_to_word, udint_to_dword, udint_to_lword, ulint_to_byte, ulint_to_word, ulint_to_dword, ulint_to_lword
lword_to_lreal, lreal_to_lword, dword_to_real, real_to_dword
bool_to_byte, bool_to_word, bool_to_dword, bool_to_lword
byte_to_bool, word_to_bool, dword_to_bool, lword_to_bool
bool_to_sint, bool_to_int, bool_to_dint, bool_to_lint, bool_to_usint, bool_to_uint, bool_to_udint, bool_to_ulint
time_to_ltime, ltime_to_time, dt_to_date, dt_to_ldate, dt_to_tod, dt_to_ltod, dt_to_ldt, ldt_to_date, ldt_to_ldate, ldt_to_tod, ldt_to_ltod, ldt_to_dt, tod_to_ltod, ltod_to_tod
char_to_byte, char_to_word, char_to_dword, char_to_lword, wchar_to_word, wchar_to_dword, wchar_to_lword
string_to_wstring, wstring_to_string, char_to_wchar, wchar_to_char, char_to_string, string_to_char, wchar_to_wstring, wstring_to_wchar
to_sint, to_int, to_dint, to_lint, to_usint, to_uint, to_udint, to_ulint, to_real, to_lreal, to_bool, to_byte, to_word, to_dword, to_lword, to_time, to_ltime, to_date, to_ldate, to_tod, to_ltod, to_dt, to_ldt, to_string, to_wstring, to_char, to_wchar
abs, sqrt, ln, log, exp, sin, cos, tan, asin, acos, atan, atan2, add, mul, sub, div, mod, expt
len, left, right, mid, concat, insert, delete, replace, find
add_time, add_ltime, add_tod_time, add_ltod_ltime, add_dt_time, add_ldt_ltime, sub_time, sub_ltime, sub_date_date, sub_ldate_ldate, sub_tod_time, sub_ltod_ltime, sub_tod_tod, sub_ltod_ltod, sub_dt_time, sub_ldt_ltime, sub_dt_dt, sub_ldt_ldt, mul_time, mul_ltime, div_time, div_ltime, concat_date_tod, concat_date_ltod, concat_date, concat_tod, concat_ltod, concat_dt, concat_ldt, split_date, split_tod, split_ltod, split_dt, split_ldt, day_of_week
real_trunc_sint, real_trunc_int, real_trunc_dint, real_trunc_lint, real_trunc_usint, real_trunc_uint, real_trunc_udint, real_trunc_ulint, lreal_trunc_sint, lreal_trunc_int, lreal_trunc_dint, lreal_trunc_lint, lreal_trunc_usint, lreal_trunc_uint, lreal_trunc_udint, lreal_trunc_ulint, trunc_sint, trunc_int, trunc_dint, trunc_lint, trunc_usint, trunc_uint, trunc_udint, trunc_ulint
byte_bcd_to_sint, byte_bcd_to_int, byte_bcd_to_dint, byte_bcd_to_lint, byte_bcd_to_usint, byte_bcd_to_uint, byte_bcd_to_udint, byte_bcd_to_ulint, word_bcd_to_sint, word_bcd_to_int, word_bcd_to_dint, word_bcd_to_lint, word_bcd_to_usint, word_bcd_to_uint, word_bcd_to_udint, word_bcd_to_ulint, dword_bcd_to_sint, dword_bcd_to_int, dword_bcd_to_dint, dword_bcd_to_lint, dword_bcd_to_usint, dword_bcd_to_uint, dword_bcd_to_udint, dword_bcd_to_ulint, lword_bcd_to_sint, lword_bcd_to_int, lword_bcd_to_dint, lword_bcd_to_lint, lword_bcd_to_usint, lword_bcd_to_uint, lword_bcd_to_udint, lword_bcd_to_ulint, bcd_to_sint, bcd_to_int, bcd_to_dint, bcd_to_lint, bcd_to_usint, bcd_to_uint, bcd_to_udint, bcd_to_ulint, sint_to_bcd_byte, sint_to_bcd_word, sint_to_bcd_dword, sint_to_bcd_lword, int_to_bcd_byte, int_to_bcd_word, int_to_bcd_dword, int_to_bcd_lword, dint_to_bcd_byte, dint_to_bcd_word, dint_to_bcd_dword, dint_to_bcd_lword, lint_to_bcd_byte, lint_to_bcd_word, lint_to_bcd_dword, lint_to_bcd_lword, usint_to_bcd_byte, usint_to_bcd_word, usint_to_bcd_dword, usint_to_bcd_lword, uint_to_bcd_byte, uint_to_bcd_word, uint_to_bcd_dword, uint_to_bcd_lword, udint_to_bcd_byte, udint_to_bcd_word, udint_to_bcd_dword, udint_to_bcd_lword, ulint_to_bcd_byte, ulint_to_bcd_word, ulint_to_bcd_dword, ulint_to_bcd_lword, to_bcd_byte, to_bcd_word, to_bcd_dword, to_bcd_lword
to_big_endian, to_little_endian, from_big_endian, from_little_endian
ctu_int, ctu_dint, ctu_lint, ctu_udint, ctu_ulint, ctd_int, ctd_dint, ctd_lint, ctd_udint, ctd_ulint, ctud_int, ctud_dint, ctud_lint, ctud_udint, ctud_ulint
tp, tp_time, tp_ltime, ton, ton_time, ton_ltime, tof, tof_time, tof_ltime
| 形式 | 例 | 詳細 |
|---|---|---|
*_TO_** | int_to_real | 型付き変換 |
TO_** | to_real | オーバーロード変換 |
*_TRUNC_** | real_trunc_int | 型付き切り捨て |
TRUNC_** | trunc_int | オーバーロード切り捨て |
*_BCD_TO_** | word_bcd_to_int | bcd→整数 (deprecated) |
BCD_TO_** | bcd_to_int | bcd→整数オーバーロード (deprecated) |
**_TO_BCD_* | int_to_bcd_word | 整数→bcd (deprecated) |
TO_BCD_** | to_bcd_word | 整数→bcd オーバーロード (deprecated) |
| 関数 | 型 | 説明 |
|---|---|---|
abs | any_num | 絶対値 |
sqrt | any_real | 平方根 |
ln | any_real | 自然対数 |
log | any_real | 常用対数 |
exp | any_real | 自然指数 |
sin | any_real | サイン |
cos | any_real | コサイン |
tan | any_real | タンジェント |
asin | any_real | アークサイン |
acos | any_real | アークコサイン |
atan | any_real | アークタンジェント |
atan2 | any_real | atan2(y,x) |
add | any_magnitude | 加算 |
mul | any_magnitude | 乗算 |
sub | any_magnitude | 減算 |
div | any_magnitude | 除算 |
mod | any_int | 剰余 |
expt | any_real/num | 冪乗 |
| 関数 | 説明 |
|---|---|
len | 文字列長 |
left | 左部分文字列 |
right | 右部分文字列 |
mid | 中間部分文字列 |
concat | 連結 (拡張可能) |
insert | 挿入 |
delete | 削除 |
replace | 置換 |
find | 検索 |
| 関数(代表) | 説明 |
|---|---|
add_time/add_ltime | 時間加算 |
sub_time/sub_ltime | 時間減算 |
mul_time/mul_ltime | 時間×スカラー |
div_time/div_ltime | 時間÷スカラー |
mod_time/mod_ltime | 時間の剰余 |
concat_date_tod等 | 日時合成 |
split_date等 | 日時分解 |
day_of_week | 曜日取得 |
| 関数 | 説明 |
|---|---|
to_big_endian | ビッグエンディアン変換 |
to_little_endian | リトルエンディアン変換 |
from_big_endian | ビッグエンディアンから変換 |
from_little_endian | リトルエンディアンから変換 |
is_valid | real/lreal 有効値チェック |
is_valid_bcd | bcd 有効値チェック (deprecated) |
| FB名 | 説明 |
|---|---|
sr | セット優先 双安定 |
rs | リセット優先 双安定 |
r_trig | 立ち上がりエッジ検出 |
f_trig | 立ち下がりエッジ検出 |
ctu/ctu_int/ctu_dint/ctu_lint/ctu_udint/ctu_ulint/ctu_uint | アップカウンタ |
ctd/ctd_int/ctd_dint/ctd_lint/ctd_udint/ctd_ulint/ctd_uint | ダウンカウンタ |
ctud/ctud_int/ctud_dint/ctud_lint/ctud_udint/ctud_ulint/ctud_uint | アップ/ダウンカウンタ |
ton/ton_time/ton_ltime | オンディレイタイマー |
tof/tof_time/tof_ltime | オフディレイタイマー |
tp/tp_time/tp_ltime | パルスタイマー |
| 形式 | 説明 | 例 |
|---|---|---|
*_TO_** | 型付き変換。*が入力型、**が出力型 | int_to_real |
TO_** | オーバーロード変換。入力型はコンテキストから推論 | to_real |
*_TRUNC_** | 型付き切り捨て変換(浮動小数点 → 整数) | real_trunc_int |
TRUNC_** | オーバーロード切り捨て変換 | trunc_int |
*_bcd_to_** | bcd エンコードビット列 → 整数(型付き、deprecated) | word_bcd_to_int |
bcd_to_** | bcd エンコードビット列 → 整数(オーバーロード、deprecated) | bcd_to_int |
**_to_bcd_* | 整数 → bcd エンコードビット列(型付き、deprecated) | int_to_bcd_word |
to_bcd_** | 整数 → bcd エンコードビット列(オーバーロード、deprecated) | to_bcd_word |
注記:bcd 変換 (
*_bcd_to_**等) は iec 61131-3 Ed.4 で deprecated であり、次版では削除される予定。
real/lreal→ 整数変換で入力が NaN または ±∞ の場合の演算関数でのオーバーフローはエラーとして定義される。変換関数とは区別する)参照実装:Python int,float, C99 (int),(float), IEC 60559 丸め規則
浮動小数点 → 整数の変換は最近偶数への丸め(iec 60559):
real_to_int(1.5)= 2(最近偶数)real_to_int(2.5)= 2(最近偶数)real_to_int(1.6)= 2real_to_int(-1.6)= -2*_TRUNC_**/TRUNC_**— 切り捨て変換ゼロ方向切り捨て(truncation toward zero):
trunc_int(1.6)= 1trunc_int(-1.6)= -1| ソース型 | → lreal | → real | → lint | → dint | → int | → sint | → ulint | → udint | → uint | → usint |
|---|---|---|---|---|---|---|---|---|---|---|
| lreal | — | 丸め | 丸め | 丸め | 丸め | 丸め | 丸め | 丸め | 丸め | 丸め |
| real | 値保持 | — | 丸め | 丸め | 丸め | 丸め | 丸め | 丸め | 丸め | 丸め |
| lint | 精度損失可 | 精度損失可 | — | 範囲確認 | 範囲確認 | 範囲確認 | 範囲確認 | 範囲確認 | 範囲確認 | 範囲確認 |
| dint | 値保持 | 精度損失可 | 値保持 | — | 範囲確認 | 範囲確認 | 範囲確認 | 範囲確認 | 範囲確認 | 範囲確認 |
| int | 値保持 | 値保持 | 値保持 | 値保持 | — | 範囲確認 | 値保持 | 値保持 | 範囲確認 | 範囲確認 |
| sint | 値保持 | 値保持 | 値保持 | 値保持 | 値保持 | — | 範囲確認 | 範囲確認 | 範囲確認 | 範囲確認 |
| ulint | 精度損失可 | 精度損失可 | 範囲確認 | 範囲確認 | 範囲確認 | 範囲確認 | — | 範囲確認 | 範囲確認 | 範囲確認 |
| udint | 値保持 | 精度損失可 | 値保持 | 範囲確認 | 範囲確認 | 範囲確認 | 値保持 | — | 範囲確認 | 範囲確認 |
| uint | 値保持 | 値保持 | 値保持 | 値保持 | 範囲確認 | 範囲確認 | 値保持 | 値保持 | — | 範囲確認 |
| usint | 値保持 | 値保持 | 値保持 | 値保持 | 値保持 | 範囲確認 | 値保持 | 値保持 | 値保持 | — |
エッジケース(数値型変換):
| 変換 | 入力条件 | 結果 | 根拠 |
|---|---|---|---|
| real/lreal → 整数 | NaN | エラー | (独自解釈仕様)NaN は有効な実数値でない |
| real/lreal → 整数 | +∞ | エラー | (独自解釈仕様)無限大は整数型で表現不能 |
| real/lreal → 整数 | -∞ | エラー | (独自解釈仕様)同上 |
| real/lreal → 整数 | -0.0 | 0 | (独自解釈仕様)−0.0 → 0(IEC 60559 丸め: round-half-to-even) |
| real/lreal → 整数 | 値域外 | エラー | |
| lreal → real | lreal > REAL_MAX | エラー | (独自解釈仕様)IEEE 754 では +∞ だが本仕様ではエラーとする |
| lint → lreal | lintが 2⁵³ を超える | 精度損失(丸め) | (独自解釈仕様)IEEE 754 double は仮数部 52 ビット |
| 整数 → bool | 0→false, 非0 →true | — | (独自解釈仕様)C99 と同様 |
| bool → 整数 | false→0,true→1 | — | (独自解釈仕様) |
参照実装:Python int.from_bytes/int.to_bytes, C99 memcpyによるビットパターンコピー
注記:テーブルの「下位コピー」は「最下位バイト(8ビット)単位でのコピー」を意味する。例: lword(64bit) → byte(8bit) は最下位8ビット(バイト0)のみコピー。
| ソース | → lword | → dword | → word | → byte | → bool |
|---|---|---|---|---|---|
| lword | — | 下位コピー | 下位コピー | 下位コピー | 最下位ビット |
| dword | 0埋め拡張 | — | 下位コピー | 下位コピー | 最下位ビット |
| word | 0埋め拡張 | 0埋め拡張 | — | 下位コピー | 最下位ビット |
| byte | 0埋め拡張 | 0埋め拡張 | 0埋め拡張 | — | 最下位ビット |
| bool | 0または1 | 0または1 | 0または1 | 0または1 | — |
エッジケース(ビット型変換):
| 変換 | 入力条件 | 結果 | 根拠 |
|---|---|---|---|
| lword_to_lreal | lword#16#7FF8000000000000 | NaN | (独自解釈仕様)ビットパターンが IEEE 754 quiet NaN に対応。変換自体は有効 |
| dword_to_real | dword#16#FF800000 | −∞ | (独自解釈仕様)ビットパターンが IEEE 754 −∞ に対応 |
| byte_to_bool | byte#16#FE(最下位ビット=0) | false | 最下位ビットのみ参照 |
| byte_to_bool | byte#1 | true | 最下位ビット = 1 |
文字型との変換:
| 変換 | 説明 |
|---|---|
char_to_byte | バイナリコピー |
byte_to_char | バイナリコピー |
char_to_word | 0埋め拡張 |
wchar_to_word | バイナリコピー |
word_to_wchar | バイナリコピー |
dword_to_uchar | バイナリコピー |
uchar_to_dword | バイナリコピー |
参照実装:Python struct.pack/struct.unpack, C99 memcpyによるビットパターン再解釈
| 変換(代表) | 説明 |
|---|---|
lword_to_lreal | バイナリコピー(8 bytes) |
dword_to_real | バイナリコピー(4 bytes) |
lreal_to_lword | バイナリコピー(8 bytes) |
real_to_dword | バイナリコピー(4 bytes) |
lword_to_lint | バイナリコピー |
dword_to_dint | バイナリコピー |
word_to_int | バイナリコピー |
byte_to_sint | バイナリコピー |
エッジケース(ビット↔数値型変換):
| 変換 | 入力条件 | 結果 | 根拠 |
|---|---|---|---|
dword_to_real | dword#16#7FC00000 | NaN | (独自解釈仕様)ビットパターンが quiet NaN |
byte_to_sint | byte#16#FF | sint#-1 | バイナリコピー(符号ビット = 1) |
word_to_int | word#16#8000 | int#-32768 | バイナリコピー(INT_MIN) |
| 関数名 | 変換内容 | 注記 |
|---|---|---|
ltime_to_time | ltime → time | 値域外は実装依存、精度損失可 |
time_to_ltime | time → ltime | 値域外は実装依存、精度損失可 |
ldt_to_dt | ldt → dt | 値域外は実装依存、精度損失可 |
ldt_to_date | ldt → date | 日付部分のみ抽出、値域外は実装依存 |
ldt_to_ldate | ldt → ldate | 日付部分のみ抽出 |
ldt_to_ltod | ldt → ltod | 時刻部分のみ抽出 |
ldt_to_tod | ldt → tod | 時刻部分のみ抽出、精度損失可 |
dt_to_ldt | dt → ldt | 値域外は実装依存、精度損失可 |
dt_to_date | dt → date | 日付部分のみ抽出、値域外は実装依存 |
dt_to_ldate | dt → ldate | 日付部分のみ抽出 |
dt_to_ltod | dt → ltod | 時刻部分のみ抽出、値域外は実装依存 |
dt_to_tod | dt → tod | 時刻部分のみ抽出、値域外は実装依存 |
ltod_to_tod | ltod → tod | 値域外は実装依存、精度損失可 |
tod_to_ltod | tod → ltod | 値域外は実装依存、精度損失可 |
ldate_to_date | ldate → date | 値域外は実装依存 |
date_to_ldate | date → ldate | — |
| 関数名 | 変換内容 |
|---|---|
wstring_to_string | wstring → string(表現不可文字は実装依存) |
ustring_to_string | ustring → string(表現不可文字は実装依存) |
ustring_to_wstring | ustring → wstring(表現不可文字は実装依存) |
string_to_wstring | string → wstring |
string_to_ustring | string → ustring |
wstring_to_ustring | wstring → ustring |
string_to_char | string の先頭1文字を抽出(空文字列は実装依存) |
wstring_to_wchar | wstring の先頭1文字を抽出(空文字列は実装依存) |
ustring_to_uchar | ustring の先頭1文字を抽出(空文字列は実装依存) |
char_to_string | char → 1文字の string |
wchar_to_wstring | wchar → 1文字の wstring |
uchar_to_ustring | uchar → 1文字の ustring |
wchar_to_char | wchar → char(表現不可は実装依存) |
uchar_to_char | uchar → char(表現不可は実装依存) |
uchar_to_wchar | uchar → wchar(表現不可は実装依存) |
char_to_wchar | char → wchar |
char_to_uchar | char → uchar |
wchar_to_uchar | wchar → uchar |
char_to_usint | char → コードポイント値(usint) |
wchar_to_uint | wchar → コードポイント値(uint) |
uchar_to_udint | uchar → コードポイント値(udint) |
usint_to_char | コードポイント → char(無効コードポイントは実装依存) |
uint_to_wchar | コードポイント → wchar(無効コードポイントは実装依存) |
udint_to_uchar | コードポイント → uchar(無効コードポイントは実装依存) |
add_int)も使用可能。abs— 絶対値| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_num | 入力値 |
| 戻り値 | — | any_num | |in| |
動作:out:= |in|
参照実装:Python abs, C99 abs/labs/fabs, IEEE 754-2019
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in = 0 | 0 | 自明 |
in = -0.0(real/lreal) | +0.0 | IEEE 754: abs(−0) = +0 |
in = +∞ | +∞ | IEEE 754 |
in = -∞ | +∞ | IEEE 754 |
in = NaN | エラー | (独自解釈仕様)NaN は有効な実数値でない |
in = sint#-128等(INT_MIN) | エラー | (独自解釈仕様)補数表現最小値の絶対値は同型で表現不能 |
sqrt— 平方根| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_real | 入力値 |
| 戻り値 | — | any_real | √in |
動作:out:= √in
エラー条件:in < 0の場合はエラー。
参照実装:Python math.sqrt, C99 sqrt(3), IEEE 754-2019 squareRoot
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in = 0.0 | 0.0 | IEEE 754 |
in = +∞ | +∞ | IEEE 754 |
in = -0.0 | 0.0 | (独自解釈仕様)real 型では −0.0 は 0.0 と等価とみなす |
in = NaN | エラー | (独自解釈仕様)NaN は有効な実数値でない |
ln— 自然対数| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_real | 入力値 |
| 戻り値 | — | any_real | ln(in) |
エラー条件:in <= 0の場合はエラー。
参照実装:Python math.log, C99 log(3)
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in = 1.0 | 0.0 | 自明(log₁₀(1) = 0) |
in = +∞ | +∞ | IEEE 754 / C99 |
in = -0.0 | エラー | (独自解釈仕様)−0.0 は 0.0 と等価とみなし log(0) はエラー |
in = NaN | エラー | (独自解釈仕様)NaN は有効な実数値でない |
参照実装:Python math.log, C99 log(3), IEEE 754-2019
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in = 1.0 | 0.0 | 自明(ln(1) = 0) |
in = +∞ | +∞ | IEEE 754 / C99 |
in = -0.0 | エラー | (独自解釈仕様)−0.0 は 0.0 と等価とみなし ln(0) はエラー |
in = NaN | エラー | (独自解釈仕様)NaN は有効な実数値でない |
log— 常用対数(底 10)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_real | 入力値 |
| 戻り値 | — | any_real | log₁₀(in) |
エラー条件:in <= 0の場合はエラー。
参照実装:Python math.log10, C99 log10(3), IEEE 754-2019
exp— 自然指数| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_real | 入力値 |
| 戻り値 | — | any_real | e^in |
参照実装:Python math.exp, C99 exp(3), IEEE 754-2019
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in = 0.0 | 1.0 | 自明 |
in = +∞ | +∞ | IEEE 754 / C99 |
in = -∞ | 0.0 | IEEE 754 / C99 |
in = NaN | エラー | (独自解釈仕様)NaN は有効な実数値でない |
| 結果がオーバーフロー | エラー | (独自解釈仕様)IEEE 754 では +∞ を返すが本仕様ではエラーとする |
sin— サイン| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_real | ラジアン単位の角度 |
| 戻り値 | — | any_real | sin(in) |
参照実装:Python math.sin, C99 sin(3), IEEE 754-2019
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in = 0.0 | 0.0 | 自明 |
in = -0.0 | -0.0 | IEEE 754 |
in = +∞ | エラー | (独自解釈仕様)IEEE 754 では NaN を返すが本仕様ではエラーとする |
in = -∞ | エラー | (独自解釈仕様)同上 |
in = NaN | エラー | (独自解釈仕様)NaN は有効な実数値でない |
cos— コサイン| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_real | ラジアン単位の角度 |
| 戻り値 | — | any_real | cos(in) |
参照実装:Python math.cos, C99 cos(3), IEEE 754-2019
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in = 0.0 | 1.0 | 自明 |
in = +∞ | エラー | (独自解釈仕様)IEEE 754 では NaN を返すが本仕様ではエラーとする |
in = -∞ | エラー | (独自解釈仕様)同上 |
in = NaN | エラー | (独自解釈仕様)NaN は有効な実数値でない |
tan— タンジェント| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_real | ラジアン単位の角度 |
| 戻り値 | — | any_real | tan(in) |
参照実装:Python math.tan, C99 tan(3)
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in = 0.0 | 0.0 | 自明 |
in ≈ π/2(最近傍 float) | 実装依存の大きな有限値 | (独自解釈仕様)π/2 は IEEE 754 で厳密に表現不能 |
in = +∞ | エラー | (独自解釈仕様)IEEE 754 では NaN を返すが本仕様ではエラーとする |
in = -∞ | エラー | (独自解釈仕様)同上 |
in = NaN | エラー | (独自解釈仕様)NaN は有効な実数値でない |
asin— アークサイン(主値)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_real | 入力値 [-1.0, 1.0] |
| 戻り値 | — | any_real | arcsin(in)[ラジアン] |
エラー条件:|in| > 1.0の場合はエラー。
参照実装:Python math.asin, C99 asin(3)
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in = 0.0 | 0.0 | 自明 |
in = 1.0 | +π/2(≈ 1.5707963…) | C99 |
in = -1.0 | -π/2 | C99 |
in = NaN | エラー | (独自解釈仕様)NaN は有効な実数値でない |
acos— アークコサイン(主値)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_real | 入力値 [-1.0, 1.0] |
| 戻り値 | — | any_real | arccos(in)[ラジアン] |
エラー条件:|in| > 1.0の場合はエラー。
参照実装:Python math.acos, C99 acos(3)
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in = 1.0 | 0.0 | C99 |
in = 0.0 | +π/2 | C99 |
in = -1.0 | π(≈ 3.14159265…) | C99 |
in = NaN | エラー | (独自解釈仕様)NaN は有効な実数値でない |
atan— アークタンジェント(主値)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_real | 入力値 |
| 戻り値 | — | any_real | arctan(in)[ラジアン] |
参照実装:Python math.atan, C99 atan(3), IEEE 754-2019
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in = 0.0 | 0.0 | 自明 |
in = -0.0 | -0.0 | IEEE 754 |
in = +∞ | +π/2 | C99 |
in = -∞ | -π/2 | C99 |
in = NaN | エラー | (独自解釈仕様)NaN は有効な実数値でない |
atan2— atan2(y, x)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
Y | 入力 | any_real | y 座標 |
X | 入力 | any_real | x 座標 |
| 戻り値 | — | any_real | 正のx軸からの角度 [ラジアン, (-π, π]] |
動作:座標(X, Y)の正のx軸からの角度を返す。
上半平面(Y > 0)は正の角度、下半平面(Y < 0)は負の角度。
参照実装:Python math.atan2, C99 atan2(3), IEEE 754-2019
エッジケース:
| Y | X | 結果 | 根拠 |
|---|---|---|---|
+0.0 | +0.0 | +0.0 | (独自解釈仕様)C99: atan2(+0,+0) = +0 |
+0.0 | -0.0 | +π | C99 |
-0.0 | +0.0 | -0.0 | IEEE 754 |
-0.0 | -0.0 | -π | C99 |
+∞ | +∞ | +π/4 | C99 |
+∞ | -∞ | +3π/4 | C99 |
-∞ | +∞ | -π/4 | C99 |
-∞ | -∞ | -3π/4 | C99 |
| NaN(いずれか) | — | エラー | (独自解釈仕様)NaN は有効な実数値でない |
add— 加算| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1,in2,...inn | 入力 | any_magnitude | 加算する値(2入力以上、拡張可能) |
| 戻り値 | — | any_magnitude | in1 in2... inn |
動作:out:= in1 in2... inn
演算子+としても使用可能。
参照実装:C99 算術演算子+
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
| 整数オーバーフロー | エラー | |
| real/lreal オーバーフロー | エラー | (独自解釈仕様)IEEE 754 では +∞ を返すが本仕様ではエラーとする |
in1 = +∞, in2 = -∞ | エラー | (独自解釈仕様)IEEE 754 では NaN を返すが本仕様ではエラーとする |
| NaN 入力 | エラー | (独自解釈仕様)NaN は有効な実数値でない |
mul— 乗算| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1,in2,...inn | 入力 | any_magnitude | 乗算する値(2入力以上、拡張可能) |
| 戻り値 | — | any_magnitude | in1 * in2 *... * inn |
演算子*としても使用可能。
参照実装:C99 算術演算子*
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
| 整数オーバーフロー | エラー | |
| real/lreal オーバーフロー | エラー | (独自解釈仕様)IEEE 754 では ±∞ を返すが本仕様ではエラーとする |
0.0 × +∞ | エラー | (独自解釈仕様)IEEE 754 では NaN を返すが本仕様ではエラーとする |
| NaN 入力 | エラー | (独自解釈仕様)NaN は有効な実数値でない |
sub— 減算| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1 | 入力 | any_magnitude | 被減数 |
in2 | 入力 | any_magnitude | 減数 |
| 戻り値 | — | any_magnitude | in1 - in2 |
演算子-としても使用可能。
参照実装:C99 算術演算子-
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
整数オーバーフロー(例:sint#127 - (-1)) | エラー | |
| real/lreal オーバーフロー | エラー | (独自解釈仕様)IEEE 754 では ±∞ を返すが本仕様ではエラーとする |
+∞ - +∞ | エラー | (独自解釈仕様)IEEE 754 では NaN を返すが本仕様ではエラーとする |
| NaN 入力 | エラー | (独自解釈仕様)NaN は有効な実数値でない |
div— 除算| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1 | 入力 | any_magnitude | 被除数 |
in2 | 入力 | any_magnitude | 除数 |
| 戻り値 | — | any_magnitude | in1 / in2 |
動作:整数除算はゼロ方向切り捨て:7 / 3 = 2、(-7) / 3 = -2。
演算子/としても使用可能。
エラー条件:in2 = 0のとき(ゼロ除算)はエラー。
参照実装:C99 算術演算子/
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in2 = 0(整数) | エラー | |
in2 = 0.0(real/lreal) | エラー | (独自解釈仕様)IEEE 754 では ±∞ を返すが本仕様ではエラーとする |
in1 = 0.0, in2 = 0.0 | エラー | (独自解釈仕様)IEEE 754 では NaN を返すが本仕様ではエラーとする |
in1 = +∞, in2 = +∞ | エラー | (独自解釈仕様)IEEE 754 では NaN を返すが本仕様ではエラーとする |
| NaN 入力 | エラー | (独自解釈仕様)NaN は有効な実数値でない |
(-7) / 2(整数) | -3 | ゼロ方向切り捨て(IEC, 既出) |
mod— 剰余| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1 | 入力 | any_int | 被除数 |
in2 | 入力 | any_int | 除数 |
| 戻り値 | — | any_int | in1 mod in2 |
言語制限:ST言語ではキーワード(演算子)のため関数呼び出し不可。LD/FBD言語では関数として使用可能。
動作:out:= in1 - (in1 / in2) * in2(切り捨て除算の剰余)
演算子modとしても使用可能。
参照実装:C99 演算子%(整数)
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
(-7) mod 3 | -1 | (独自解釈仕様)剰余の符号は被除数に従う(ゼロ方向切り捨て除算の剰余) |
7 mod (-3) | 1 | (独自解釈仕様)同上 |
(-7) mod (-3) | -1 | (独自解釈仕様)同上 |
in1 = 0 | 0 | 自明 |
in2 = 0 | エラー | (ゼロ除算) |
expt— 冪乗| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1 | 入力 | any_real | 底(base) |
in2 | 入力 | any_num | 指数(exponent) |
| 戻り値 | — | any_real | in1 ^ in2 |
演算子**としても使用可能。
注記:in2が整数型の場合も同じ計算式が適用されるが、負の整数指数(例:0.0 ^ -2)はエラーとなる(→エッジケース表参照)
参照実装:Python **演算子, C99 pow(3), IEEE 754-2019
エッジケース:
| in1 | in2 | 結果 | 根拠 |
|---|---|---|---|
0.0 | 0.0 | 1.0 | (独自解釈仕様)C99:pow(0,0)= 1.0 |
0.0 | 正の実数 | 0.0 | C99 |
0.0 | 負の実数 | エラー | (独自解釈仕様)C99 では +∞ を返すが本仕様ではエラーとする |
| 負の実数 | 非整数 | エラー | (独自解釈仕様)虚数になるためエラー |
1.0 | +∞ | 1.0 | C99 |
+∞ | ±0.0 | 1.0 | (独自解釈仕様)C99:pow(+inf, ±0)= 1.0 |
| NaN 入力(いずれか) | — | エラー | (独自解釈仕様)NaN は有効な実数値でない |
| 結果がオーバーフロー | エラー | (独自解釈仕様)IEEE 754 では +∞ を返すが本仕様ではエラーとする |
入力型any_bit、シフト量N: any_int。
オーバーロードおよび型付きバリアント(例:shl_byte)が使用可能。
エラー条件:
N < 0の場合はエラー。
shl— 左シフト| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_bit | 入力値 |
N | 入力 | any_int | シフトビット数 |
| 戻り値 | — | any_bit | 左シフト結果 |
動作:inをNビット左シフト。右端は0で埋める。
例:in = byte#2#0001_1001, N = 3→2#1100_1000
参照実装:C99 演算子<<(符号なし型), Python <<
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
N = 0 | inと同じ | 自明 |
N ≥ bit_width(in) | 0 | (独自解釈仕様)C99 では未定義動作; Python x << n= 0 相当 |
N < 0 | エラー |
shr— 右シフト| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_bit | 入力値 |
N | 入力 | any_int | シフトビット数 |
| 戻り値 | — | any_bit | 右シフト結果 |
動作:inをNビット右シフト。左端は0で埋める。
例:in = byte#2#0001_1001, N = 3→2#0000_0011
参照実装:C99 演算子>>(符号なし型), Python >>
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
N = 0 | inと同じ | 自明 |
N ≥ bit_width(in) | 0 | (独自解釈仕様)C99 では未定義動作; 符号なし右シフトとして全ビット消去 |
N < 0 | エラー | |
| shr は符号なしシフト | 左端は常に0補填 |
rol— 左ローテーション| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_bit | 入力値 |
N | 入力 | any_int | ローテーションビット数 |
| 戻り値 | — | any_bit | 左ローテーション結果 |
動作:inをNビット左回転(最上位ビットが最下位ビットに循環)。
例:in = byte#2#0001_1001, N = 3→2#1100_1000
参照実装:Java Integer.rotateLeft, C99:(x << n) | (x >> (W-n))
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
N = 0 | inと同じ | 自明 |
N = bit_width(in) | inと同じ(1周回転) | 自明 |
N > bit_width(in) | rol(in, N mod bit_width(in))と同等 | (独自解釈仕様)有効シフト量 = N mod 型ビット幅 |
N < 0 | エラー |
ror— 右ローテーション| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_bit | 入力値 |
N | 入力 | any_int | ローテーションビット数 |
| 戻り値 | — | any_bit | 右ローテーション結果 |
動作:inをNビット右回転(最下位ビットが最上位ビットに循環)。
例:in = byte#2#0001_1001, N = 3→2#0010_0011
参照実装:Java Integer.rotateRight, C99:(x >> n) | (x << (W-n))
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
N = 0 | inと同じ | 自明 |
N = bit_width(in) | inと同じ(1周回転) | 自明 |
N > bit_width(in) | ror(in, N mod bit_width(in))と同等 | (独自解釈仕様)有効シフト量 = N mod 型ビット幅 |
N < 0 | エラー |
言語制限:ST言語ではキーワード(演算子)のため関数呼び出し不可。LD/FBD言語では関数として使用可能。
全ビット論理演算関数はオーバーロードで、any_bit型に適用可能。
型付きバリアント(例:and_word)も使用可能。
and— ビット論理 and| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1,in2,...INn | 入力 | any_bit | 入力値(2入力以上、拡張可能) |
| 戻り値 | — | any_bit | in1 and in2 and... and INn |
演算子&としても使用可能。
or— ビット論理 or| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1,in2,...INn | 入力 | any_bit | 入力値(2入力以上、拡張可能) |
| 戻り値 | — | any_bit | in1 or in2 or... or INn |
xor— ビット論理 xor| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1,in2,...INn | 入力 | any_bit | 入力値(2入力以上、拡張可能) |
| 戻り値 | — | any_bit | in1 xor in2 xor... xor INn |
not— ビット論理 not| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_bit | 入力値 |
| 戻り値 | — | any_bit | not in |
注記:notは非拡張(入力は1つのみ)。
and/or/xorは論理演算として機能する。and/or/xorはすべての入力を評価する(短絡評価なし)。(独自解釈仕様)not bool#1=bool#0、not bool#0=bool#1(1ビットの論理 NOT)。notを代替できる。選択関数はすべてのデータ型にオーバーロードされる。
move— 代入| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any | 入力値 |
| 戻り値 | — | any | inと同じ値 |
動作:out:= in
注記:moveは入力1つ・出力1つの固定インターフェース。
sel— 2値選択| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
G | 入力 | bool | セレクト入力 |
in0 | 入力 | any | G = falseのとき選択される値 |
in1 | 入力 | any | G = trueのとき選択される値 |
| 戻り値 | — | any | 選択された値 |
動作:G = false→out:= in0G = true→out:= in1
注記:列挙型にも適用可能(, )。ただしG入力には列挙型は不可。
max— 最大値(拡張可能)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1,in2,...inn | 入力 | any_elementary | 比較する値(2入力以上、拡張可能) |
| 戻り値 | — | any_elementary | 最大値 |
動作:out:= max(in1, in2,..., inn)
min— 最小値(拡張可能)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1,in2,...inn | 入力 | any_elementary | 比較する値(2入力以上、拡張可能) |
| 戻り値 | — | any_elementary | 最小値 |
動作:out:= min(in1, in2,..., inn)
limit— 制限| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
mn | 入力 | any_elementary | 下限値 |
in | 入力 | any_elementary | 入力値 |
mx | 入力 | any_elementary | 上限値 |
| 戻り値 | — | any_elementary | 制限された値 |
動作:out:= min(max(in, mn), mx)
エラー条件:mn > mxの場合はエラー。
参照実装:Python max(mn, min(in, mx))
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in < mn | mn | 自明 |
in > mx | mx | 自明 |
mn = mx | mn(=mx) | 自明 |
mn > mx | エラー | (独自解釈仕様)不正範囲はエラー(暗黙的スワップはしない) |
| NaN 入力(real/lreal) | エラー | (独自解釈仕様)NaN は比較不能 |
mux— N入力選択(拡張可能)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
K | 入力 | any_int | セレクトインデックス |
in0,in1,...inn-1 | 入力 | any | 選択候補(n入力、拡張可能) |
| 戻り値 | — | any | inkの値 |
動作:out:= ink(K番目の入力を選択、0-indexed)
エラー条件:Kの値が0... n-1の範囲外の場合はエラー。
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
K = 0 | in0 | 自明 |
K = n-1 | in_{n-1} | 自明(最後の入力) |
K < 0 | エラー | (独自解釈仕様)負のインデックスは無効 |
K ≥ n | エラー |
注記:- 型付きバリアント:MUX_*_**(*はKの型、**はinおよび戻り値の型)。
K入力には列挙型は不可。
比較関数はany_elementary型にオーバーロードされる。ne以外はすべて拡張可能(2入力以上)。
ビット列型の比較は最上位ビットから最下位ビットへビット単位で行う(符号なし整数比較と同等)。
異なる長さの文字列を比較するとき、短い方の右端に0を補完して比較する。
エッジケース(比較関数共通):
| 入力条件 | 結果 | 根拠 |
|---|---|---|
| NaN 入力(real/lreal) | エラー | (独自解釈仕様)NaN は比較不能; 事前にis_validで確認が必要 |
+0.0と-0.0の比較 | 等価(eq=true、lt/gt=false) | IEEE 754: +0 = −0 |
同一値のgt/lt | false | 自明(同値は大小なし) |
gt— より大きい(降順)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1,in2,...inn | 入力 | any_elementary | 比較値(2入力以上、拡張可能) |
| 戻り値 | — | bool | 結果 |
動作:out:= (in1 > in2) and (in2 > in3) and... and (inn-1 > inn)
演算子>としても使用可能。
gt(A, B, C)はA > B > C(数学的連鎖)を意味し、A > B and B > Cと等価。
ge— 以上(単調減少)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1,in2,...inn | 入力 | any_elementary | 比較値(2入力以上、拡張可能) |
| 戻り値 | — | bool | 結果 |
動作:out:= (in1 >= in2) and (in2 >= in3) and... and (inn-1 >= inn)
演算子>=としても使用可能。
eq— 等値| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1,in2,...inn | 入力 | any_elementary | 比較値(2入力以上、拡張可能) |
| 戻り値 | — | bool | 結果 |
動作:out:= (in1 = in2) and (in2 = in3) and... and (inn-1 = inn)
演算子=としても使用可能。列挙型にも適用可能。
le— 以下(単調増加)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1,in2,...inn | 入力 | any_elementary | 比較値(2入力以上、拡張可能) |
| 戻り値 | — | bool | 結果 |
動作:out:= (in1 <= in2) and (in2 <= in3) and... and (inn-1 <= inn)
演算子<=としても使用可能。
lt— より小さい(昇順)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1,in2,...inn | 入力 | any_elementary | 比較値(2入力以上、拡張可能) |
| 戻り値 | — | bool | 結果 |
動作:out:= (in1 < in2) and (in2 < in3) and... and (inn-1 < inn)
演算子<としても使用可能。
ne— 不等値(非拡張)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1 | 入力 | any_elementary | 比較値1 |
in2 | 入力 | any_elementary | 比較値2 |
| 戻り値 | — | bool | 結果 |
動作:out:= (in1 <> in2)(入力は2つのみ、拡張不可)
演算子<>としても使用可能。列挙型にも適用可能。
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
ne(NaN, NaN) | エラー | (独自解釈仕様)NaN 入力はエラー(IEEE 754: NaN ≠ NaN = true だが本仕様ではエラー) |
ne(+0.0, -0.0) | false | (独自解釈仕様)IEEE 754: +0 = −0 |
1, 2,..., L。Lは文字列長)。any_stringは string / wstring / ustring のいずれか。any_charsはany_stringに加えて char / wchar / uchar も受け付ける。エラー条件(共通):- 整数入力パラメータ(L,P等)が 0 未満の場合はエラー。
境界ケース(共通):
| 状況 | 挙動 | 根拠 |
|---|---|---|
L = 0(left/right/mid) | ''(空文字列)を返す | (独自解釈仕様)Python s[0:0]=''に準拠 |
L = 0(delete) | inと同じ(変化なし) | (独自解釈仕様)0文字削除 |
L = 0(replace) | in1のP位置にin2を挿入した結果 | (独自解釈仕様)0文字置換 = 挿入と等価 |
P = 0(insert) | 先頭に挿入(プリペンド) | (独自解釈仕様)P=0 は「0文字目の後」= 先頭前 |
P = 0(mid/delete/replace) | エラー | (独自解釈仕様)1-indexed; 最小値は 1 |
in2 = ''(find) | 1 | (独自解釈仕様)空文字列は常に先頭位置で見つかるとみなす |
注記:
Pの最小有効値は関数によって異なる。insertのみP=0(先頭挿入)が有効。mid、delete、replaceではPは 1-indexed の文字位置を指すためP >= 1が必須。いずれもP < 0はエラー。
len— 文字列長| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_string | 対象文字列 |
| 戻り値 | — | any_int | 文字数 |
例:len('astring')= 7
left— 左部分文字列| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_string | 対象文字列 |
L | 入力 | any_int | 取り出す文字数 |
| 戻り値 | — | any_string | 先頭L文字 |
例:left('astr', 3)='ast'
参照実装:Python s[:L]
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
L = 0 | '' | (独自解釈仕様) |
L = len(in) | inと同じ | 自明 |
L > len(in) | エラー | (独自解釈仕様)範囲外 |
right— 右部分文字列| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_string | 対象文字列 |
L | 入力 | any_int | 取り出す文字数 |
| 戻り値 | — | any_string | 末尾L文字 |
例:right('astr', 3)='str'
参照実装:Python s[len(s)-L:](1-indexed のためs[-L:]と同等)
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
L = 0 | '' | (独自解釈仕様) |
L = len(in) | inと同じ | 自明 |
L > len(in) | エラー | (独自解釈仕様)範囲外 |
mid— 中間部分文字列| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_string | 対象文字列 |
L | 入力 | any_int | 取り出す文字数 |
P | 入力 | any_int | 開始位置(1-indexed) |
| 戻り値 | — | any_string | 位置PからL文字 |
例:mid('astr', 2, 2)='st'(2文字目から2文字)
参照実装:Python s[P-1: P-1+L]
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
L = 0 | '' | (独自解釈仕様) |
P = 1, L = len(in) | inと同じ(全体取得) | 自明 |
P L - 1 > len(in) | エラー | (独自解釈仕様)範囲外 |
P = 0 | エラー | (独自解釈仕様)1-indexed; P の最小値は 1 |
concat— 文字列連結(拡張可能)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1,in2,...INn | 入力 | any_chars | 連結する文字列(2入力以上、拡張可能) |
| 戻り値 | — | any_string | 全入力を連結した文字列 |
例:concat('ab', 'cd', 'E')='abcdE'
注記:char/wchar/uchar型も入力として受け付ける。
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
入力のいずれかが'' | その入力は無視(空文字連結は元の文字列に等しい) | 自明 |
全入力が'' | '' | 自明 |
| 合計長が実装最大長を超える | エラー |
insert— 文字列挿入| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1 | 入力 | any_string | 元の文字列 |
in2 | 入力 | any_chars | 挿入する文字列または文字 |
P | 入力 | any_int | 挿入位置(この位置の文字の後に挿入) |
| 戻り値 | — | any_string | 挿入後の文字列 |
例:insert('abc', 'xy', 2)='abxyc'(2文字目の後に'xy'を挿入)
参照実装:Python s[:P] ins s[P:](P は 0-indexed に変換済み)
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
P = 0 | in2 in1(先頭に挿入) | (独自解釈仕様)P=0 は先頭前を意味する |
P = len(in1) | in1 in2(末尾に追加) | 自明 |
P > len(in1) | エラー | (独自解釈仕様)範囲外 |
in2 = '' | in1と同じ | 自明 |
delete— 文字列削除| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_string | 元の文字列 |
L | 入力 | any_int | 削除する文字数 |
P | 入力 | any_int | 削除開始位置(1-indexed) |
| 戻り値 | — | any_string | 削除後の文字列 |
例:delete('abxyc', 2, 3)='abc'(3文字目から2文字を削除)
参照実装:Python s[:P-1] s[P-1+L:]
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
L = 0 | inと同じ | (独自解釈仕様)0文字削除 |
P = 1, L = len(in) | ''(全削除) | 自明 |
P L - 1 > len(in) | エラー | (独自解釈仕様)範囲外 |
P = 0 | エラー | (独自解釈仕様)1-indexed; P の最小値は 1 |
replace— 文字列置換| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1 | 入力 | any_string | 元の文字列 |
in2 | 入力 | any_chars | 置換後の文字列または文字 |
L | 入力 | any_int | 置換する文字数 |
P | 入力 | any_int | 置換開始位置(1-indexed) |
| 戻り値 | — | any_string | 置換後の文字列 |
例:replace('abcde', 'X', 2, 3)='abxe'(3文字目から2文字を'X'に置換)
参照実装:Python s[:P-1] new s[P-1+L:]
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
L = 0 | in1の P 位置にin2を挿入した結果 | (独自解釈仕様)0文字置換 = 挿入と等価 |
in2 = '' | in1の P 位置から L 文字を削除した結果 | (独自解釈仕様)空文字への置換 = 削除と等価 |
P L - 1 > len(in1) | エラー | (独自解釈仕様)範囲外 |
P = 0 | エラー | (独自解釈仕様)1-indexed; P の最小値は 1 |
find— 文字列検索| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in1 | 入力 | any_string | 検索対象の文字列 |
in2 | 入力 | any_chars | 検索する文字列または文字 |
| 戻り値 | — | any_int | 最初に見つかった位置(1-indexed)、見つからない場合は 0 |
例:find('abcbc', 'bc')= 2(最初の'bc'は2文字目から始まる)
参照実装:Python s.find(sub)1(0-indexed → 1-indexed 変換)
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in2 = ''(空文字列) | 1 | (独自解釈仕様)空文字列は常に先頭で見つかるとみなす |
in1 = ''かつin2 ≠ '' | 0(見つからない) | 自明 |
in1 = in2 | 1 | 自明(先頭から完全一致) |
in1に複数マッチ | 最小インデックス(左端) | (独自解釈仕様)Pythonfindと同様 |
| 見つからない | 0 |
add_time)はオーバーロードなしで特定の型に対して動作する。time,date,tod,dtおよび L prefix 型)はany_magnitudeに含まれない。加減演算には本ファイルの専用関数を使用すること。IEC 61131-3 は型の内部表現を規定しない。本仕様では以下の独自解釈を採用する。
| 型 | 内部表現 | エポック / 基準点 | 有効範囲 |
|---|---|---|---|
time | 符号付き整数(ナノ秒) | T#0s(ゼロ持続時間) | T#−106751d... ~ T#106751d... |
ltime | 符号付き整数(ナノ秒) | LT#0s | time より広い範囲 |
date | 符号なし整数(日数) | D#1970-01-01(Unix 日付エポック) | D#1970-01-01 ~ 実装最大日付 |
ldate | 符号なし整数(日数) | LD#1970-01-01 | date より広い範囲 |
tod | 符号なし整数(ナノ秒) | TOD#00:00:00(当日開始) | TOD#00:00:00 ~ TOD#23:59:59.999999999 |
ltod | 符号なし整数(ナノ秒) | LTOD#00:00:00 | tod と同じ |
dt | 符号なし整数(ナノ秒) | DT#1970-01-01-00:00:00(Unix epoch) | DT#1970-01-01-00:00:00 ~ 実装最大 |
ldt | 符号なし整数(ナノ秒) | LDT#1970-01-01-00:00:00 | dt より広い範囲 |
(独自解釈仕様)エポックおよび内部表現はすべて実装者が決定。上記は Python
datetime/timedeltaベースの実装を想定した設計。
参照実装:Python datetime.timedelta(加減算),datetime.date,datetime.datetime,datetime.time
| 関数名 | in1 | in2 | out | 説明 |
|---|---|---|---|---|
add_time | time | time | time | 時間 時間 |
add_ltime | ltime | ltime | ltime | 長時間 長時間 |
add_tod_time | tod | time | tod | 時刻 時間 |
add_ltod_ltime | ltod | ltime | ltod | 長時刻 長時間 |
add_dt_time | dt | time | dt | 日時 時間 |
add_ldt_ltime | ldt | ltime | ldt | 長日時 長時間 |
| 関数名 | in1 | in2 | out | 説明 |
|---|---|---|---|---|
sub_time | time | time | time | 時間 - 時間 |
sub_ltime | ltime | ltime | ltime | 長時間 - 長時間 |
sub_date_date | date | date | time | 日付差 |
sub_ldate_ldate | ldate | ldate | ltime | 長日付差 |
sub_tod_time | tod | time | tod | 時刻 - 時間 |
sub_ltod_ltime | ltod | ltime | ltod | 長時刻 - 長時間 |
sub_tod_tod | tod | tod | time | 時刻差 |
sub_ltod_ltod | ltod | ltod | ltime | 長時刻差 |
sub_dt_time | dt | time | dt | 日時 - 時間 |
sub_ldt_ltime | ldt | ltime | ldt | 長日時 - 長時間 |
sub_dt_dt | dt | dt | time | 日時差 |
sub_ldt_ldt | ldt | ldt | ltime | 長日時差 |
| 関数名 | in1 | in2 | out | 説明 |
|---|---|---|---|---|
mul_time | time | any_num | time | 時間 × スカラー |
mul_ltime | ltime | any_num | ltime | 長時間 × スカラー |
div_time | time | any_num | time | 時間 ÷ スカラー |
div_ltime | ltime | any_num | ltime | 長時間 ÷ スカラー |
div_time(time ÷ time) | time | time | lint | 時間 ÷ 時間(商、ゼロ方向切り捨て) |
div_ltime(ltime ÷ ltime) | ltime | ltime | lint | 長時間 ÷ 長時間 |
mod_time | time | time | time | 時間 mod 時間 |
mod_ltime | ltime | ltime | ltime | 長時間 mod 長時間 |
div_time_lreal | time | time | lreal | 時間 ÷ 時間(lreal 商) |
div_ltime_lreal | ltime | ltime | lreal | 長時間 ÷ 長時間(lreal 商) |
注記:- 時間 ÷ 時間の整数除算はゼロ方向切り捨て:7s / 3s = 2、(-7s) / 3s = -2。
out:= in1 - (in1 / in2) * in2(/は整数除算、ゼロ方向切り捨て)
エッジケース(時間演算共通):
| 入力条件 | 結果 | 根拠 |
|---|---|---|
| 結果が型の値域外 | エラー | |
sub_time(T#0s, T#1s) | T#-1s(負の持続時間) | (独自解釈仕様)time は符号付き持続時間 |
sub_date_date(D#2000-01-01, D#2001-01-01) | 負の time 値 | (独自解釈仕様)date 型は符号なし整数だが、戻り値 time 型は符号付き持続時間のため負値が可能 |
mul_time(T#1s, 0) | T#0s | 自明 |
mul_time(T#1s, -1) | T#-1s | (独自解釈仕様)負のスカラーは符号反転 |
div_time(T#10s, 0) | エラー | (独自解釈仕様)ゼロ除算 |
mod_time(T#10s, T#0s) | エラー | (独自解釈仕様)ゼロ mod |
パラメータが通常の範囲を超えた場合、上位の単位に繰り上がり(または借り)が発生する:
| 規則 |
|---|
second=n, millisecond=m⟺second=n+1, millisecond=m-1000 |
minute=n, second=m⟺minute=n+1, second=m-60 |
hour=n, minute=m⟺hour=n+1, minute=m-60 |
day=n, hour=m⟺day=n+1, hour=m-24 |
year=k, month=n, day=m⟺year=k, month=n+1, day=m-dayOfMonth(k,n) |
year=n, month=m⟺year=n+1, month=m-12 |
参照実装:Python datetime.datetime(year, month, day,...),datetime.date(year, month, day),datetime.time(hour, minute, second, microsecond)
| 関数名 | 入力 | 出力 |
|---|---|---|
concat_date_tod | date, tod | dt |
concat_date_ltod | date, ltod | ldt |
concat_ldate_tod | ldate, tod | ldt |
concat_ldate_ltod | ldate, ltod | ldt |
| 関数名 | 入力 | 出力 |
|---|---|---|
concat_date | year, month, day (any_int) | date |
concat_ldate | year, month, day (any_int) | ldate |
| 関数名 | 入力 | 出力 |
|---|---|---|
concat_tod | hour, minute, second, millisecond (any_int) | tod |
concat_ltod | hour, minute, second, millisecond, microsecond, nanosecond (any_int) | ltod |
| 関数名 | 入力 | 出力 |
|---|---|---|
concat_dt | year, month, day, hour, minute, second, millisecond (any_int) | dt |
concat_ldt | year, month, day, hour, minute, second, millisecond (any_int) | ldt |
注記:year 入力は少なくとも16ビット型が必要(有効な年を表現するため)。
エッジケース(concat 関数共通):
| 入力条件 | 結果 | 根拠 |
|---|---|---|
month = 13 | 翌年の1月(繰り上がり) | 繰り上がり規則 |
hour = 24(concat_tod) | エラー | (独自解釈仕様)tod 型の有効範囲は 0–23 時; 繰り上がり規則で正規化できない場合はエラー |
hour = 25(concat_tod の繰り上がり中間値) | 内部的に 01:00 相当にノーマライズ後 tod 範囲内に収まれば有効 | (独自解釈仕様)最終結果が tod 範囲外ならエラー |
| 最終結果が型の値域外 | エラー | (独自解釈仕様)繰り上がり後もオーバーフローする場合 |
year = 0(concat_date) | エラー | (独自解釈仕様)年 0 は無効(プロレプティック暦では有効だが本仕様では不可) |
| 関数名 | 入力 | 出力 | 説明 |
|---|---|---|---|
split_date | date | year, month, day (any_int) | 日付分解 |
split_ldate | ldate | year, month, day (any_int) | 長日付分解 |
split_tod | tod | hour, minute, second, millisecond (any_int) | 時刻分解 |
split_ltod | ltod | hour, minute, second, millisecond (any_int) | 長時刻分解 |
split_dt | dt | year, month, day, hour, minute, second, millisecond (any_int) | 日時分解 |
split_ldt | ldt | year, month, day, hour, minute, second, millisecond, (microsecond, nanosecond) (any_int) | 長日時分解 |
注記:出力パラメータの any_int 型は実装者が決定する。
day_of_week— 曜日取得参照実装:Python datetime.date.isoweekday/datetime.date.weekday, C99 struct tm.tm_wday
| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | date | 対象日付 |
| 戻り値 | — | any_int | 曜日番号 |
動作:0=日曜, 1=月曜, 2=火曜, 3=水曜, 4=木曜, 5=金曜, 6=土曜
(独自解釈仕様)IEC 61131-3 は曜日番号の体系を規定しない。
本仕様では C99struct tm tm_wday(0=日曜〜6=土曜)を採用する。
※ ISO 8601 は 1=月曜〜7=日曜、Pythondatetime.weekdayは 0=月曜〜6=日曜。
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in = D#1970-01-01(木曜日) | 4 | (独自解釈仕様)1970-01-01 は木曜日(C99 基準) |
in = D#2000-01-01(土曜日) | 6 | (独自解釈仕様)検証: Python datetime(2000,1,1).weekday= 5(月曜0起点)→ +1 mod 7 = 6(日曜0起点) |
注記:出力の any_int 型は実装者が決定する。
エンディアン変換関数は、実装者固有の内部エンディアンから、または内部エンディアンへの変換を行う。
エンディアンの定義:ビッグエンディアン:最上位バイトが先頭(低アドレス)に格納される。リトルエンディアン:最下位バイトが先頭(低アドレス)に格納される。
対応する入出力型:any_int(16ビット以上)any_bit(16ビット以上)any_realwcharwstringucharany_durationany_date- 上記要素からなる配列・構造体
注記:入力と出力の型は同じでなければならない。すでに変換先のエンディアンである場合、データ表現は変更されない。
配列/構造体に対しては、各要素/メンバへの再帰的適用として定義される。
エッジケース(エンディアン変換):
| 入力条件 | 結果 | 根拠 |
|---|---|---|
1バイト型(byte,char,sint,usint) | 変換なし(パススルー) | (独自解釈仕様)1バイトにはバイト順序の概念がない |
bool型 | 変換なし(パススルー) | (独自解釈仕様)1ビット型にはバイト順序がない |
| すでに目的のエンディアンの場合 | 変換なし | |
to_big_endian(to_little_endian(x)) | xと等価でない場合がある | (独自解釈仕様)実装が big-endian ならto_little_endianでバイト反転、再びto_big_endianでさらに反転 |
to_big_endian— ビッグエンディアンに変換| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any | 入力値 |
| 戻り値 | — | any | ビッグエンディアン形式に変換した値 |
to_little_endian— リトルエンディアンに変換| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any | 入力値 |
| 戻り値 | — | any | リトルエンディアン形式に変換した値 |
from_big_endian— ビッグエンディアンから変換| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any | ビッグエンディアン形式の入力値 |
| 戻り値 | — | any | 実装者固有エンディアンに変換した値 |
from_little_endian— リトルエンディアンから変換| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any | リトルエンディアン形式の入力値 |
| 戻り値 | — | any | 実装者固有エンディアンに変換した値 |
以下の選択・比較関数は列挙型の入力にも適用可能。
ただし、selのG入力およびmuxのK入力には列挙型を使用してはならない。
| 関数名 | 制約 |
|---|---|
sel | G入力には列挙型不可 |
mux | K入力には列挙型不可 |
eq(=) | — |
ne(<>) | — |
is_valid— 有効値チェック| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_real | チェックする浮動小数点値 |
| 戻り値 | — | bool | 有効な場合true |
動作:inが NaN(Not-a-Number)の場合 →falseinが +∞ または -∞ の場合 →false- それ以外 →true
参照実装:Python math.isfinite, C99 isfinite(3)
エッジケース:
| 入力条件 | 結果 | 根拠 |
|---|---|---|
in = NaN | false | |
in = +∞ | false | |
in = -∞ | false | |
in = -0.0 | true | (独自解釈仕様)IEEE 754: −0.0 は有限な実数値 |
in = 0.0 | true | 自明 |
inが整数型 | true | (独自解釈仕様)整数型には NaN/∞ が存在しないため常にtrue |
inが time/date/tod/dt 型 | true | (独自解釈仕様)時間型には NaN/∞ が存在しないため常にtrue |
(独自解釈仕様)整数型・時間型への適用は実装者拡張時の参考。IEC base spec では
any_realのみが定義対象。
注記:実装者は real/lreal 以外の追加型にis_validを拡張することができる(結果は実装依存)。
is_valid_bcd— bcd 有効値チェック(deprecated)⚠️deprecated:iec 61131-3 Ed.4 で deprecated。次版での削除が予定される。
| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | 入力 | any_bit | チェックする bcd 値 |
| 戻り値 | — | bool | 有効な bcd の場合true |
動作:inが有効な bcd エンコード(各4ビットニブルが 0–9 の範囲内)の場合 →true- それ以外 →false
双安定(Bistable)ファンクションブロックはフリップフロップに相当し、セット・リセット入力で出力状態を保持します。
双安定要素はセット/リセット入力を持つフリップフロップである。
出力q1の初期値はfalse(bool 型のデフォルト値)。
sr— セット優先双安定セットが優先される双安定ファンクションブロック。s1 = trueかつr = trueの場合、q1 = true(s1 が優先される)。
| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
s1 | var_input | bool | セット入力(優先) |
r | var_input | bool | リセット入力 |
q1 | var_output | bool | 出力 |
別名入力名(同義):
| 別名 | 対応 |
|---|---|
set1 | s1 |
reset | r |
q1:= s1 or (not r and q1);
真理値表:
| s1 | r | q1(次) |
|---|---|---|
| false | false | q1(保持) |
| false | true | false |
| true | false | true |
| true | true | true(s1 優先) |
s1とrが同時にtrueの場合、s1が優先されるためq1 = trueとなる。初期状態・エッジケース:
| 状況 | 結果 | 根拠 |
|---|---|---|
| コールドリスタート(初回スキャン前) | q1 = false | bool 型のデフォルト初期値 |
初回スキャン:s1 = false, r = false | q1 = false(保持、初期値のまま) | 真理値表 |
初回スキャン:s1 = true, r = false | q1 = true | 真理値表 |
初回スキャン:s1 = false, r = true | q1 = false | 真理値表 |
セット入力(s1)とリセット入力(r)を持ちます。両入力が同時にtrueの場合、セット(q1 = true)が優先されます。
// sr: セット優先双安定ファンクションブロック // q1:= s1 or (q1 and not r) var ff: sr; set_in: bool; reset_in: bool; out: bool; end_var ff(s1:= set_in, r:= reset_in); out:= ff.q1; // ロング入力名でも呼び出し可能 ff(set1:= set_in, reset:= reset_in);
rs— リセット優先双安定リセットが優先される双安定ファンクションブロック。s = trueかつr1 = trueの場合、q1 = false(r1 が優先される)。
| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
s | var_input | bool | セット入力 |
r1 | var_input | bool | リセット入力(優先) |
q1 | var_output | bool | 出力 |
別名入力名(同義):
| 別名 | 対応 |
|---|---|
set | s |
reset1 | r1 |
q1:= not r1 and (s or q1);
真理値表:
| s | r1 | q1(次) |
|---|---|---|
| false | false | q1(保持) |
| false | true | false(r1 優先) |
| true | false | true |
| true | true | false(r1 優先) |
sとr1が同時にtrueの場合、r1が優先されるためq1 = falseとなる。初期状態・エッジケース:
| 状況 | 結果 | 根拠 |
|---|---|---|
| コールドリスタート(初回スキャン前) | q1 = false | bool 型のデフォルト初期値 |
初回スキャン:s = false, r1 = false | q1 = false(保持) | 真理値表 |
初回スキャン:s = true, r1 = false | q1 = true | 真理値表 |
初回スキャン:s = false, r1 = true | q1 = false | 真理値表 |
初回スキャン:s = true, r1 = true | q1 = false(r1 優先) | 真理値表 |
セット入力(s)とリセット入力(r1)を持ちます。両入力が同時にtrueの場合、リセット(q1 = false)が優先されます。
// rs: リセット優先双安定ファンクションブロック // q1:= (s or q1) and not r1 var ff: rs; set_in: bool; reset_in: bool; out: bool; end_var ff(s:= set_in, r1:= reset_in); out:= ff.q1;
エッジ検出FBは入力信号の変化(立上り・立下り)を1スキャンだけ検出します。
エッジ検出FBは、入力clkの信号遷移を1スキャンだけ検出し、q = trueを出力する。
その後のスキャンではq = falseに戻る。
r_trig— 立ち上がりエッジ検出入力clkがfalse → trueに遷移したスキャンでq = true、
それ以外のスキャンではq = false。
| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
clk | var_input | bool | クロック入力 |
q | var_output | bool | 立ち上がりパルス出力 |
| 変数名 | 型 | 初期値 | 説明 |
|---|---|---|---|
m | bool | false | 前スキャンのclk値 |
function_block r_trig var_input clk: bool; end_var var_output Q: bool; end_var var M: bool; end_var Q:= clk and not M; M:= clk; end_function_block
clk ______|‾‾‾‾‾‾‾‾‾|_____|‾‾‾‾‾‾|____ Q ________|‾|_____________|‾|________ ↑ 検出 ↑ 検出
clkがfalse → trueになったスキャンのみq = true。clk = trueが継続する間はq = false。clk = trueの場合はq = trueとなる(mの初期値がfalseのため)。r_edge修飾子付きvar_inputを持つ fb の内部でr_trigが暗黙的に使用される( 項 13)。エッジケース:
| スキャン状況 | clk | M(前) | Q | M(後) | 根拠 |
|---|---|---|---|---|---|
| コールドリスタート直後(1回目) | true | false(初期値) | true | true | q = true and not false = true |
| コールドリスタート直後(1回目) | false | false(初期値) | false | false | q = false and not false = false |
連続true(2回目以降) | true | true | false | true | パルスは1スキャンのみ |
連続false | false | false | false | false | 変化なし |
false → true(遷移スキャン) | true | false | true | true | 立ち上がり検出 |
clk入力がfalse → trueに変化したスキャンのみqがtrueになります。次のスキャンではfalseに戻ります。
// r_trig: 立上りエッジ(0→1)を1スキャンだけ検出 // 内部実装: q:= clk and not m; m:= clk; var trig: r_trig; clk: bool; pulse: bool; end_var trig(clk:= clk); pulse:= trig.q; // clkの立上りスキャンのみtrue
f_trig— 立ち下がりエッジ検出入力clkがtrue → falseに遷移したスキャンでq = true、
それ以外のスキャンではq = false。
| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
clk | var_input | bool | クロック入力 |
q | var_output | bool | 立ち下がりパルス出力 |
| 変数名 | 型 | 初期値 | 説明 |
|---|---|---|---|
m | bool | false | 前スキャンのnot clk値 |
function_block f_trig var_input clk: bool; end_var var_output Q: bool; end_var var M: bool; end_var Q:= not clk and not M; M:= not clk; end_function_block
clk ‾‾‾‾‾‾|___________|‾‾‾‾|_________|‾ Q _______________|‾|___________|‾|____ ↑ 検出 ↑ 検出
clkがtrue → falseになったスキャンのみq = true。clk = falseが継続する間はq = false。clk = falseの場合はq = not false and not false = trueとなる(clk = falseかつmの初期値がfalseのため)。f_edge修飾子付きvar_inputを持つ fb の内部でf_trigが暗黙的に使用される( 項 13)。エッジケース:
| スキャン状況 | clk | M(前) | Q | M(後) | 根拠 |
|---|---|---|---|---|---|
| コールドリスタート直後(1回目) | false | false(初期値) | true | true | q = not false and not false = true |
| コールドリスタート直後(1回目) | true | false(初期値) | false | false | q = not true and not false = false |
連続false(2回目以降) | false | true | false | true | パルスは1スキャンのみ |
連続true | true | false | false | false | 変化なし |
true → false(遷移スキャン) | false | false | true | true | 立ち下がり検出 |
注意:コールドリスタート後
clk = falseの場合、f_trigは即座にパルス(q = true)を出力する。
これは M の初期値がfalseであるため。接続先の論理で考慮が必要。(独自解釈仕様)
clk入力がtrue → falseに変化したスキャンのみqがtrueになります。
// f_trig: 立下りエッジ(1→0)を1スキャンだけ検出 // 内部実装: q:= not clk and m; m:= clk; var trig: f_trig; clk: bool; pulse: bool; end_var trig(clk:= clk); pulse:= trig.q; // clkの立下りスキャンのみtrue
カウンタFBは入力パルスを計数します。cu/cd入力は立上りエッジ(bool r_edge型)で計数します。型付き版(ctu_int等)と多重定義版(ctu等)があります。計数の上限(pvmax)・下限(pvmin)の値は実装依存です(int型なら通常32767/−32768)。
カウンタFBは、入力パルスの立ち上がりエッジをカウントする。
エッジ検出は内部でr_edgeデータ型修飾子により実施される。
各カウンタは以下の型バリアントを持つ。pvおよびcvの型が異なるだけで、動作は同一。
| 型バリアント | pv / cv 型 |
|---|---|
ctu/ctu_int | int |
ctu_dint | dint |
ctu_lint | lint |
ctu_udint | udint |
ctu_ulint | ulint |
ctu_uint | uint |
(ctd,ctudも同様の6型バリアントを持つ)
PVmax/PVminPVmax: 型の最大値(実装依存)PVmin: 型の最小値。符号付き整数では負の値、符号なし整数では0。r_edge修飾子についてカウンタのcu/cd入力はvar_input bool r_edge修飾子付きで宣言されている。
これは呼び出し元がエッジ検出を行い、FB 内部には「今スキャンで立ち上がりエッジがあったか」を示す bool 値として渡されることを意味する。
FB 内部の ST 等価コードでは単純な bool 値として記述する。
ctu— アップカウンタ (Up-Counter)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
cu | var_input | bool r_edge | カウントアップ入力(立ち上がりエッジ有効) |
R | var_input | bool | リセット入力(trueでカウント値を 0 にリセット) |
pv | var_input | int (*) | プリセット値 |
Q | var_output | bool | cv >= pvのときtrue |
cv | var_output | int (*) | 現在のカウント値 |
(*) 型バリアントにより dint / lint / udint / ulint / uint に変わる。
if R then cv:= 0; elsif cu and (cv < PVmax) then cv:= cv 1; end_if; Q:= (cv >= pv);
R = trueのときcvをリセット(リセット優先)。R = falseかつcuの立ち上がりエッジがあり、cv < PVmaxのときcvをインクリメント。cv = PVmaxのとき、cu立ち上がりエッジが来てもcvは変化しない(オーバーフロー防止)。Qはcv >= pvのときtrue。ctu_udint等の符号なし型バリアントではcvの最小値が0であるため、リセットはcv:= 0のまま。エッジケース:
| 状況 | 結果 | 根拠 |
|---|---|---|
| コールドリスタート時 | cv = 0,Q = false(pv > 0の場合) | (独自解釈仕様)bool/整数型のデフォルト初期値 0 |
pv = 0 | Q = true(cv = 0 >= 0) | 自明(初期状態から Q がアクティブ) |
pv < 0(符号付き型) | Q = true(cv = 0 >= 負値) | (独自解釈仕様)pv < 0 は有効; Q はリセット直後から true |
cv = PVmaxの状態でcu立ち上がり | cvは変化しない(飽和) | |
R = trueとcuエッジが同時 | cv:= 0(リセット優先) |
pvを動作中に変更した場合の動作(独自解釈仕様):
変更後のpv | 動作 |
|---|---|
現在のcvより大 | カウント動作を継続。cv ≥ 新 pvになった時点でq = true。 |
現在のcv以下 | 直ちにq = true。cvは変化しない。 |
pvに負数を設定した場合、r = trueでリセット後cv = 0になった時点でcv ≥ pvが成立するため直ちにq = trueになる。その後cuが変化してもcvの加算は行われない。
cu(立上りエッジ)のたびにcvを1加算します。rでcvをリセット(0)します。cv >= pvのときq = true。
// ctu: アップカウンタ(ctu_int と等価) // if r then cv:= 0; elsif cu and (cv < pvmax) then cv:= cv+1; end_if; // q:= (cv >= pv); var cnt: ctu; // または ctu_int pulse: bool; // 計数パルス(立上りエッジで+1) reset: bool; // リセット(true で cv:= 0) preset: int:= 10; // プリセット値 reached: bool; // cv >= pv のとき true count: int; // 現在の計数値 end_var cnt(cu:= pulse, r:= reset, pv:= preset); reached:= cnt.q; count:= cnt.cv;
ctd— ダウンカウンタ (Down-Counter)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
cd | var_input | bool r_edge | カウントダウン入力(立ち上がりエッジ有効) |
ld | var_input | bool | ロード入力(trueでcv:= pv) |
pv | var_input | int (*) | プリセット値 |
Q | var_output | bool | cv <= 0のときtrue |
cv | var_output | int (*) | 現在のカウント値 |
(*) 型バリアントにより変わる(同上)。
if ld then cv:= pv; elsif cd and (cv > PVmin) then cv:= cv - 1; end_if; Q:= (cv <= 0);
ld = trueのときcv:= pv(ロード優先)。ld = falseかつcdの立ち上がりエッジがあり、cv > PVminのときcvをデクリメント。cv = PVminのとき、cd立ち上がりエッジが来てもcvは変化しない(アンダーフロー防止)。Qはcv <= 0のときtrue。ctd_udint等)ではPVmin = 0であるため、cv = 0以下にはならない。エッジケース:
| 状況 | 結果 | 根拠 |
|---|---|---|
| コールドリスタート時 | cv = 0,Q = true(cv = 0 <= 0) | (独自解釈仕様)cv 初期値 = 0; 初期状態から Q がアクティブ |
pv = 0かつld = true | cv:= 0、Q = true | 自明 |
cv = PVminの状態でcd立ち上がり | cvは変化しない(飽和) | |
ld = trueとcdエッジが同時 | cv:= pv(ロード優先) | |
pv < 0(符号付き型) | cv:= pv(負値ロード)、Q = (pv <= 0) = true | (独自解釈仕様)有効 |
pvを動作中に変更した場合の動作(独自解釈仕様):
ctdのqはcv <= 0のみに依存し、pvはロード(ld = true)時にのみcvへ反映される。
ld = falseの状態でpvを変更してもcvおよびqはスキャン中に変化しない。新しいpvは次にld = trueになったときに有効になる。
pvに負数または 0 を設定した場合、ld = trueでcv:= pvにロードされた時点でcv ≤ 0が成立するため直ちにq = trueになる。
cd(立上りエッジ)のたびにcvを1減算します。ld(ロード)でcv:= pvにセットします。cv <= 0のときq = true。
// ctd: ダウンカウンタ(ctd_int と等価) // if ld then cv:= pv; elsif cd and (cv > pvmin) then cv:= cv-1; end_if; // q:= (cv <= 0); var cnt: ctd; // または ctd_int pulse: bool; // 計数パルス(立上りエッジで-1) load: bool; // ロード(true で cv:= pv) preset: int:= 5; zero: bool; // cv <= 0 のとき true count: int; end_var cnt(cd:= pulse, ld:= load, pv:= preset); zero:= cnt.q; count:= cnt.cv;
ctud— アップ/ダウンカウンタ (Up-Down Counter)| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
cu | var_input | bool r_edge | カウントアップ入力 |
cd | var_input | bool r_edge | カウントダウン入力 |
R | var_input | bool | リセット入力(trueでcv:= 0) |
ld | var_input | bool | ロード入力(trueでcv:= pv) |
pv | var_input | int (*) | プリセット値 |
qu | var_output | bool | cv >= pvのときtrue |
qd | var_output | bool | cv <= 0のときtrue |
cv | var_output | int (*) | 現在のカウント値 |
(*) 型バリアントにより変わる(同上)。
if R then cv:= 0; elsif ld then cv:= pv; else if not (cu and cd) then if cu and (cv < PVmax) then cv:= cv 1; elsif cd and (cv > PVmin) then cv:= cv - 1; end_if; end_if; end_if; qu:= (cv >= pv); qd:= (cv <= 0);
優先順位(高い順):
1.R = true→cv:= 0(リセット優先)
2.ld = true→cv:= pv(ロード優先)
3.cuとcdが同時に立ち上がりエッジ →cvは変化しない
4.cu立ち上がりエッジ → インクリメント(PVmax上限)
5.cd立ち上がりエッジ → デクリメント(PVmin下限)
cuとcdが同時にエッジを持つ場合、両者が打ち消し合いcvは変化しない。エッジケース:
| 状況 | 結果 | 根拠 |
|---|---|---|
| コールドリスタート時 | cv = 0,qu = false,qd = true | (独自解釈仕様)cv 初期値 = 0; 0 <= 0 なので qd = true |
R = trueかつld = true | cv:= 0(リセット優先) | |
pv < 0(符号付き型) | qu = (cv >= pv): cv=0 ≥ 負値 →qu = true | (独自解釈仕様)有効 |
cv = PVmaxでcuエッジ | cvは変化しない | |
cv = PVminでcdエッジ | cvは変化しない |
アップ計数(cu)とダウン計数(cd)の両方を持ちます。rでリセット(cv:= 0)、ldでロード(cv:= pv)。quはcv >= pv、qdはcv <= 0のときtrue。
// ctud: アップダウンカウンタ(ctud_int と等価) var cnt: ctud; // または ctud_int cu, cd: bool; // アップ/ダウン計数パルス reset: bool; // リセット load: bool; // ロード preset: int:= 10; qu, qd: bool; // qu: cv>=pv, qd: cv<=0 count: int; end_var cnt(cu:= cu, cd:= cd, r:= reset, ld:= load, pv:= preset); qu:= cnt.qu; qd:= cnt.qd; count:= cnt.cv;
タイマFBは時間計測に使用します。time型とltime型の多重定義版があります(例:ton、ton_time、ton_ltime)。計時動作中にptの値を変更したときの動作は実装依存です。
| パラメータ | 方向 | 型 | 説明 |
|---|---|---|---|
in | var_input | bool | タイマー起動入力 |
pt | var_input | time / ltime | プリセット時間 |
q | var_output | bool | タイマー出力 |
et | var_output | time / ltime | 経過時間 |
| 型バリアント | pt / et 型 |
|---|---|
ton/ton_time | time |
ton_ltime | ltime |
tof/tof_time | time |
tof_ltime | ltime |
tp/tp_time | time |
tp_ltime | ltime |
tonとton_timeは同義。以下の説明ではtime型バリアントで記述する。
タイマー全般エッジケース(独自解釈仕様):
| 状況 | 結果 | 根拠 |
|---|---|---|
pt = T#0sかつin = true | 同じスキャンで即座にq = true(et = T#0s) | (独自解釈仕様)et >= ptはT#0s >= T#0s = true |
pt < T#0s(負のプリセット) | in = trueになった直後のスキャンでq = true;etはT#0sに飽和 | (独自解釈仕様)IEC pseudocode:et >= 負値は常に true |
スキャン周期 >>pt | ptを超えた最初のスキャンでq = true;etはptに飽和 | (独自解釈仕様)スキャン粒度の制約 |
<CURRENT_TIME>分解能 | タイマー精度はシステムクロック分解能に依存 | (独自解釈仕様)実装者が<CURRENT_TIME>の提供方法を決定 |
| コールドリスタート時 | start = <CURRENT_TIME>,last = false,q = false,et = T#0s | (独自解釈仕様)初期値 |
| 変数名 | 型 | 説明 |
|---|---|---|
start | time / ltime | タイマー開始時刻(<current_time>で取得) |
last | bool | 前スキャンのin値 |
ton/ton_time— オンディレイタイマーinがtrueになってからpt経過後にq = trueになる。
in __________|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|_________|‾‾‾‾‾‾|_____ t0 t1 t2 t3 Q _______________________|‾‾‾‾‾|_____________|‾‾|__ t0+pt t1 t2+pt t3 et _____/‾‾‾‾‾‾‾‾‾‾\____/‾‾‾‾‾‾‾‾‾‾‾‾‾\____/‾‾\ t0 t0+pt t1 t2 t2+pt t3 0→pt pt 0 0→ pt 0
inがtrueになった瞬間にタイマーリセット(start:= cur)。in = trueが継続してet >= ptになったときq:= true、et:= pt(飽和)。inがfalseになるとすぐにq:= false、et:= 0。in = true→falseがpt未満で起きた場合、qは一度もtrueにならない。function_block ton_time var_input in: bool; pt: time; end_var var_output Q: bool; et: time; end_var var private start: time; last: bool; end_var var_temp cur: time; end_var cur:= <current_time>; if not in or not last then // in が false(タイマー停止中)または前回スキャンで false(タイマー未起動)→ リセット start:= cur; end_if et:= cur - start; Q:= in and et >= pt; if Q then if pt < T#0s then et:= T#0s; else et:= pt; // 飽和 end_if end_if last:= in; end_function_block
in = falseのとき常にstartをリセットするため、inがtrueになった瞬間から経過時間を計測する。ptに負の値を設定した場合、etはT#0sに飽和する(実装依存の範囲内)。ton(in:=A, pt:=B, Q=>C, et=>D)はtof(in:=not A, pt:=B, not Q=>C, et=>D)と意味的に等価。ton エッジケース:
| 状況 | Q | et | 根拠 |
|---|---|---|---|
in = false(常時) | false | T#0s | 自明 |
in = true,pt = T#0s | 即座にtrue | T#0s | et >= T#0sは即時成立 |
in = true,pt = T#5s, スキャン 3s 後 | false | ≈T#3s | まだ pt 未到達 |
in = true → false(pt 前) | false、et = T#0sにリセット | — | ton 動作仕様 |
ptを動作中に変更した場合の動作:
| タイマの状態 | q | 変更後のpt | 動作 |
|---|---|---|---|
計時終了後(q = true) | true | 任意 | qはtrueのまま。etも変化しない。 |
計時中(q = false) | false | 新pt≥et | 計時続行。et≥ 新ptになった時点でq = true。 |
計時中(q = false) | false | 新pt<et | 直ちにq = true、etの増加が即停止。 |
(独自解釈仕様)IEC 擬似コードでは毎サイクルq:= in and et >= ptが評価されるため、pt変更は即座に反映される。
inがtrueになってからpt時間後にqがtrueになります(オン・ディレイ)。inがfalseになると即座にq = false、et = 0に戻ります。
// ton: オン・ディレイタイマ // inがtrueになってからpt時間後にqがtrueになる var timer: ton; enable: bool; delayed: bool; elapsed: time; end_var timer(in:= enable, pt:= time#5s); delayed:= timer.q; // 5秒後にtrueになる elapsed:= timer.et; // 経過時間(0〜pt)
tof/tof_time— オフディレイタイマーinがfalseになってからpt経過後にq = falseになる。in = trueのときq = true。
in ‾‾‾‾‾‾‾‾‾‾|_______________|‾‾‾|_________|‾‾‾‾‾ t0 t1 t2 t3 Q ‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|_________|‾‾‾‾‾ t0+pt t3+pt et ______/‾‾‾‾‾‾‾‾‾‾‾‾‾\____/‾‾‾‾‾\___/‾‾‾ t0 t0+pt t2 t3 0→pt pt 0→pt 0
in = trueのときq = true、et = 0(タイマーリセット)。inがfalseになるとタイマー開始。et >= ptになるとq:= false、et:= pt(飽和)。inがfalse→trueに戻ると(pt経過前でも)タイマーリセット、qはtrueに戻る。function_block tof_time var_input in: bool; pt: time; end_var var_output Q: bool; et: time; end_var var private start: time; last: bool; end_var var_temp cur: time; end_var cur:= <current_time>; if in or last then // in が true または前回 true → リセット start:= cur; end_if et:= cur - start; Q:= in or et < pt; if not Q then if pt < T#0s then et:= T#0s; else et:= pt; // 飽和 end_if end_if last:= in; end_function_block
in = trueのとき常にstartをリセットするため、inがfalseになった瞬間から経過時間を計測する。ptを動作中に変更した場合の動作:
| タイマの状態 | q | 変更後のpt | 動作 |
|---|---|---|---|
計時中(q = true,in = false) | true | 新pt≥et | 計時続行。et≥ 新ptになった時点でq = false。 |
計時中(q = true,in = false) | true | 新pt<et | 直ちにq = false、etの増加が即停止。 |
計時終了後(q = false,in = false) | false | 新pt> 実経過時間 | et < 新 ptが再成立しqがtrueに戻る。 |
計時終了後(q = false,in = false) | false | 新pt≤ 実経過時間 | qはfalseのまま。etは新ptに飽和。 |
(独自解釈仕様)IEC 擬似コードでは毎サイクルq:= in or et < ptが評価されるため、pt変更は即座に反映される。計時終了後(q = false,in = false)はstartがリセットされずに内部の実経過時間が増え続けるため、ptを大きく増加させるとqがtrueに戻る場合がある点に注意。
inがfalseになってからpt時間後にqがfalseになります(オフ・ディレイ)。inがtrueになると即座にq = trueになります。
// tof: オフ・ディレイタイマ // inがfalseになってからpt時間後にqがfalseになる var timer: tof; enable: bool; delayed: bool; elapsed: time; end_var timer(in:= enable, pt:= time#2s); delayed:= timer.q; // inがfalseになってからpt時間後にfalseになる elapsed:= timer.et; // 経過時間(0〜pt)
tp/tp_time— パルスタイマーinの立ち上がりエッジでq = trueになり、pt経過後にq = falseになる。q = trueの間はinの変化を無視する(単安定マルチバイブレータ)。
in ________|‾‾‾‾‾‾‾‾‾‾‾‾‾|__|‾‾‾‾‾‾‾‾|____|‾‾‾‾‾‾‾‾|___ t0 t1 t2 t3 t4 t5 Q _________|‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾‾|_____________|‾‾‾‾‾‾‾‾‾‾‾|__ t0 t0+pt t4 t4+pt et ____/‾‾‾‾‾‾‾‾‾‾‾‾‾\____ /‾‾‾‾‾‾‾‾‾\ t0 pt t0+pt t4 t4+pt
inの立ち上がりエッジ(false → true)でパルス開始。q = trueの間はinの変化(t1,t2の立ち下がり・立ち上がり)を無視する。et >= ptになるとq:= false、et:= pt(飽和)。t3の立ち上がりはq = falseのときなので無視(パルス中ではないがin = falseなのでエッジはt4で発生)。function_block tp_time var_input in: bool; pt: time; end_var var_output Q: bool; et: time; end_var var private start: time; last: bool; end_var var_temp cur: time; end_var cur:= <current_time>; if not Q then // q = false の間のみエッジを監視 if in and not last then // 立ち上がりエッジ q:= true; end_if if Q or not in then start:= <current_time>; end_if end_if et:= cur - start; if et >= pt then et:= pt; // 飽和 q:= false; // pt 経過後にリセット end_if last:= in; end_function_block
q = trueの間はinの変化を一切無視する(再トリガなし)。ptの変化が実行中のタイミング動作に与える影響は実装依存( note)。ptを動作中に変更した場合の動作:
| タイマの状態 | q | 変更後のpt | 動作 |
|---|---|---|---|
計時中(q = true) | true | 新pt>et | 計時続行。et≥ 新ptになった時点でq = false。 |
計時中(q = true) | true | 新pt≤et | 直ちにq = false、etの増加が即停止。 |
計時終了後(q = false) | false | 任意 | 次の立ち上がりエッジまで効果なし。 |
(独自解釈仕様)IEC 擬似コードでは毎サイクルif et >= pt then... q:= false end_ifが評価されるため、pt変更は即座に反映される。計時終了後(q = false,in = false)はstartが毎スキャン更新されるためet = T#0sが維持され、pt変更の影響はない。
tp エッジケース:
| 状況 | Q | 根拠 |
|---|---|---|
pt = T#0sの立ち上がりエッジ | qは同スキャン内で瞬間的にtrue→falseに遷移(実質パルス幅 0) | (独自解釈仕様)ST コード上はet >= T#0sが即時成立し Q=true になるが、同スキャン末でet=ptクランプにより Q は実装次第 |
inがtrueになると、ptで指定した時間だけqがtrueになります。計時中にinが変化しても出力は変わりません(ワンショット動作)。
// tp: パルスタイマ // inの立上りでqがtrueになり、pt時間後にfalseに戻る var timer: tp; start: bool; pulse_out: bool; elapsed: time; end_var timer(in:= start, pt:= time#3s); pulse_out:= timer.q; // 3秒間のパルス出力 elapsed:= timer.et; // 経過時間