Posted to tcl by mookie at Mon Nov 10 00:11:23 GMT 2025view raw

  1. proc S a\ b {set f [string triml [join [lmap x [split [format %0[set l [string le [expr max(abs($a),abs($b))]]]lld [expr abs($a)]] ""] y [split [format %0$l\lld [expr abs($b)]] ""] {format %02d [expr $x*$y]}] ""] 0]
  2. set s [expr {$f==""?0:$f}]
  3. expr $a<0^$b<0?-$s:$s}
  4.  
  5. lmap a\ b {
  6. 0 0
  7. 302 40
  8. 302 -40
  9. -4352 448
  10. 0 6623
  11. 0 -6623
  12. 20643 -56721
  13. 63196 21220
  14. 1276 933024
  15. -1276 933024
  16. -1276 -933024
  17. 5007204555 350073039
  18. -612137119 -8088606033
  19. 3389903661 -6619166963
  20. -23082746128560880381 1116941217
  21. -668336881543038127783364011867 896431401738330915057436190556
  22. 402878826066336701417493206805490000415 312487283677673237790517973105761463808
  23. } {puts "$a $b => [S $a $b]"}

Add a comment

Please note that this site uses the meta tags nofollow,noindex for all pages that contain comments.
Items are closed for new comments after 1 week