From 03593596d4bbb983947bb9fa29ca3d8d0d0e3af8 Mon Sep 17 00:00:00 2001 From: yamasaki <114902604+ymski@users.noreply.github.com> Date: Wed, 23 Aug 2023 21:12:45 +0900 Subject: [PATCH] change to the method of determining powers of 2 using bitwise operations Signed-off-by: yamasaki <114902604+ymski@users.noreply.github.com> --- ros2caret/verb/record.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ros2caret/verb/record.py b/ros2caret/verb/record.py index 7a1f97c7..ad2fee90 100644 --- a/ros2caret/verb/record.py +++ b/ros2caret/verb/record.py @@ -12,7 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import math import os from typing import Optional @@ -190,7 +189,7 @@ def main(self, *, args): and args.subbuffer_size_ust != 8*4096: raise ValueError('the --subbuffer-size-ust option is ' 'available in iron or rolling') - if not math.log2(args.subbuffer_size_ust).is_integer(): + if args.subbuffer_size_ust & (args.subbuffer_size_ust-1): raise ValueError('--subbuffer-size-ust value must be power of two.') init_args['subbuffer_size_ust'] = args.subbuffer_size_ust @@ -198,7 +197,7 @@ def main(self, *, args): and args.subbuffer_size_kernel != 32*4096: raise ValueError('the --subbuffer-size-kernel option is ' 'available in iron or rolling') - if not math.log2(args.subbuffer_size_kernel).is_integer(): + if args.subbuffer_size_kernel & (args.subbuffer_size_kernel-1): raise ValueError('--subbuffer-size-kernel value must be power of two.') init_args['subbuffer_size_kernel'] = args.subbuffer_size_kernel init(**init_args)