소스 검색

make all numbers floating point for !calc always

horgh 16 년 전
부모
커밋
6014a6bb2d
1개의 변경된 파일5개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      calc.tcl

+ 5 - 0
calc.tcl

@@ -9,6 +9,7 @@ proc is_op {str} {
 
 proc safe_calc {nick uhost hand chan str} {
 	if {![channel get $chan calc]} { return }
+
 	foreach char [split $str {}] {
 		if {![is_op $char] && ![string is integer $char]} {
 			putserv "PRIVMSG $chan :$nick: Invalid expression for calc."
@@ -16,6 +17,10 @@ proc safe_calc {nick uhost hand chan str} {
 		}
 	}
 
+	# make all values floating point
+	set str [regsub -all -- {(\d+)} $str {[expr {\1*1.0}]}]
+	set str [subst $str]
+
 	if {[catch {expr $str} out]} {
 		putserv "PRIVMSG $chan :$nick: Invalid equation."
 		return