mathtcl

Is there any function which can be used for floating point modulo in TCL?


% set a 10.0
10.0
% set b 3.0
3.0
% puts "[expr {$a % $b}]"
can't use floating-point value as operand of "%"

I am getting the above error is there any way to do it in tcl.


Solution

  • tcl comes with a built in fmod math function that can be used with expr or as a standalone:

    set a 10.0
    set b 3.0
    puts [expr {fmod($a, $b)}]
    puts [::tcl::mathfunc::fmod $a $b]