diff --git a/src/zeek.bif b/src/zeek.bif index 6bc0382882..fffb310412 100644 --- a/src/zeek.bif +++ b/src/zeek.bif @@ -2422,6 +2422,19 @@ function int_to_count%(n: int%): count ## d: The :zeek:type:`double` to convert. ## ## Returns: The :zeek:type:`double` *d* as unsigned integer, or 0 if *d* < 0.0. +## The value returned follows typical rounding rules, as implemented +## by rint(). +function double_to_int%(d: double%): count + %{ + return zeek::val_mgr->Int(bro_int_t(rint(d))); + %} + +## Converts a :zeek:type:`double` to a :zeek:type:`int`. +## +## d: The :zeek:type:`double` to convert. +## +## Returns: The :zeek:type:`double` *d* as signed integer. The value returned +## follows typical rounding rules, as implemented by rint(). ## ## .. zeek:see:: double_to_time function double_to_count%(d: double%): count diff --git a/testing/btest/Baseline/bifs.to_int/out b/testing/btest/Baseline/bifs.to_int/out index 9c836ac56c..c0c6d56ef5 100644 --- a/testing/btest/Baseline/bifs.to_int/out +++ b/testing/btest/Baseline/bifs.to_int/out @@ -3,3 +3,7 @@ -1 4294967296 0 +3 +4 +-3 +-4 diff --git a/testing/btest/bifs/to_int.zeek b/testing/btest/bifs/to_int.zeek index 23e74030ba..17e433f975 100644 --- a/testing/btest/bifs/to_int.zeek +++ b/testing/btest/bifs/to_int.zeek @@ -8,4 +8,16 @@ event zeek_init() print to_int("-1"); print to_int("4294967296"); print to_int("not an int"); + + local a: double = 3.14; + print double_to_int(a); + + local b: double = 3.9; + print double_to_int(b); + + local c: double = -3.14; + print double_to_int(c); + + local d: double = -3.9; + print double_to_int(d); }