Allow `set_units`/`set_cmd_units` to support floats properly (#349)

This commit is contained in:
Akash Levy 2025-12-04 11:30:05 -05:00 committed by GitHub
parent aa3088885f
commit 6e16c3f189
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 32 additions and 3 deletions

View File

@ -144,7 +144,7 @@ proc check_unit { unit key suffix key_var } {
set arg_suffix [string range $value end-[expr $suffix_length - 1] end]
if { [string match -nocase $arg_suffix $suffix] } {
set arg_prefix [string range $value 0 end-$suffix_length]
if { [regexp "^(10*)?(\[Mkmunpf\])?$" $arg_prefix ignore mult prefix] } {
if { [regexp "^(10*\.?0*)?(\[Mkmunpf\])?$" $arg_prefix ignore mult prefix] } {
if { $mult == "" } {
set mult 1
}

View File

@ -167,13 +167,13 @@ proc set_unit_values { unit key suffix key_var } {
set arg_suffix [string range $value end-[expr $suffix_length - 1] end]
if { [string match -nocase $arg_suffix $suffix] } {
set arg_prefix [string range $value 0 end-$suffix_length]
if { [regexp "^(10*)?(\[Mkmunpf\])?$" $arg_prefix ignore mult prefix] } {
if { [regexp "^(10*\.?0*)?(\[Mkmunpf\])?$" $arg_prefix ignore mult prefix] } {
#puts "$arg_prefix '$mult' '$prefix'"
if { $mult == "" } {
set mult 1
}
set scale [unit_prefix_scale $unit $prefix ]
set_cmd_unit_scale $unit $scale
set_cmd_unit_scale $unit [expr $scale * $mult]
} else {
sta_error 166 "unknown unit $unit prefix '${arg_prefix}'."
}

View File

@ -158,6 +158,7 @@ record_sta_tests {
report_checks_src_attr
report_json1
report_json2
set_units_float
suppress_msg
verilog_attribute
verilog_specify

7
test/set_units_float.ok Normal file
View File

@ -0,0 +1,7 @@
time 1ns
capacitance 1pF
resistance 1kohm
voltage 1v
current 1A
power 1W
distance 1um

21
test/set_units_float.tcl Normal file
View File

@ -0,0 +1,21 @@
# set_units with floating point numbers
# start by setting the cmd units
set_cmd_units -capacitance 1000.0fF
set_cmd_units -resistance 1.0kohm
set_cmd_units -time 1.0ns
set_cmd_units -voltage 1.0v
set_cmd_units -current 1.0A
set_cmd_units -distance 1.0um
# then check the units
set_units -capacitance 1.0pF
set_units -resistance 1.0kohm
set_units -time 1.0ns
set_units -voltage 1.0v
set_units -current 1.0A
set_units -power 1.0W
set_units -distance 1.0um
# finally report the units
report_units