|
Number::Spice - handling of Spice number strings |
Number::Spice - handling of Spice number strings
use Number::Spice qw(:convert);
print spice_to_number('5u'); # 5E-6
print spice_to_number('1.0e4k'); # 1.0E7
print number_to_spice(1.0e12); # 1T
print number_to_spice(1.0e-2); # 10M (i.e. milli, not mega!)
Number::Spice was written to support the number format used in the syntax for netlists for the spice electrical circuit simulator. This number format is also used in other applications, even in different fields. Number::Spice can be used to any purpose, and does not require the installation of the spice simulator.
Spice syntax provides a shortcut for writing down numbers in scientific notation, by appending a suffix to the value which corresponds to a numeric multiplier. The following table lists the minimal suffices and the corresponding multiplier:
T 1.0E12
G 1.0E9
MEG 1.0E6
X 1.0E6
K 1.0E3
M 1.0E-3
MIL 2.54E-5 (i.e. 1/1000 inch)
U 1.0E-6
N 1.0E-9
P 1.0E-12
F 1.0E-15
A 1.0E-18
The following functions are provided. All functions are available for exporting.
is_spice_number($spice_number)split_spice_number($spice_number)Note that a regular number is also considered to be a spice number, and an empty string will be returned as the suffix in this case.
suffix_value($suffixc)suffix_value('giga') yields 1.0E9.
spice_to_number($spice_number)spice_to_number() will die() if the given number is not a spice number.
number_to_spice($number)normalize_spice_number($spice_number)spice_to_number() and number_to_spice().
In addition to the methods, the following scalars representing regular expressions are also made available for exporting:
$RE_NUMBER$RE_SPICE_SUFFIX$RE_SPICE_NUMBER/$RE_NUMBER$RE_SPICE_SUFFIX\b/ instead.
The functions and regular expressions are tagged into the following groups for easy importing:
number_to_spice() and normalize_spice_number()
$RE_NUMBER, $RE_SPICE_SUFFIX and $RE_SPICE_NUMBER
More info on the Spice format is given in the on-line Spice3 manual at the University of Exeter, located at http://newton.ex.ac.uk/teaching/CDHW/Electronics2/userguide/sec2.html#2
And to those who were looking for numbers on the Spice Girls, but unfortunately stranded here, take a peek at their official home page: http://c3.vmg.co.uk/spicegirls/ ;-)
Wim Verhaegen <wim.verhaegen@ieee.org>
Copyright (c) 2000 Wim Verhaegen. All rights reserved. This program is free software; you can redistribute and/or modify it under the same terms as Perl itself.
|
Number::Spice - handling of Spice number strings |