The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Data::SecsPack - pack and unpack numbers in accordance with SEMI E5-94

SYNOPSIS

 #####
 # Subroutine interface
 #  
 use Data::SecsPack qw(bytes2int config float2binary 
                    ifloat2binary int2bytes   
                    pack_float pack_int pack_num  
                    str2float str2int 
                    unpack_float unpack_int unpack_num);

 $big_integer = bytes2int( @bytes );

 $old_value = config( $option );
 $old_value = config( $option => $new_value);

 ($binary_magnitude, $binary_exponent) = float2binary($magnitude, $exponent, @options); 
 ($binary_magnitude, $binary_exponent) = float2binary($magnitude, $exponent, [@options]); 
 ($binary_magnitude, $binary_exponent) = float2binary($magnitude, $exponent, {@options}); 
 
 ($binary_magnitude, $binary_exponent) = ifloat2binary($imagnitude, $iexponent, @options);
 ($binary_magnitude, $binary_exponent) = ifloat2binary($imagnitude, $iexponent, [@options]);
 ($binary_magnitude, $binary_exponent) = ifloat2binary($imagnitude, $iexponent, {@options});

 @bytes = int2bytes( $big_integer );

 ($format, $floats) = pack_float($format, @string_integers);

 ($format, $integers) = pack_int($format, @string_integers);

 ($format, $numbers, @string) = pack_num($format, @strings);

 $float = str2float($string);
 (\@strings, @floats) = str2float(@strings);

 $integer = str2int($string);
 (\@strings, @integers) = str2int(@strings);

 \@ingegers = unpack_int($format, $integer_string); 
 \@floats   = unpack_float($format, $float_string); 
 \@numbers  = unpack_num($format, $number_string); 

 #####
 # Class interface
 #
 use Data::SecsPack;

 $big_integer = bytes2int( @bytes );

 ($binary_magnitude, $binary_exponent) = float2binary($magnitude, $exponent, @options); 
 ($binary_magnitude, $binary_exponent) = float2binary($magnitude, $exponent, [@options]); 
 ($binary_magnitude, $binary_exponent) = float2binary($magnitude, $exponent, {@options}); 

 ($binary_magnitude, $binary_exponent) = ifloat2binary($imagnitude, $iexponent, @options);
 ($binary_magnitude, $binary_exponent) = ifloat2binary($imagnitude, $iexponent, [@options]);
 ($binary_magnitude, $binary_exponent) = ifloat2binary($imagnitude, $iexponent, {@options});

 @bytes = int2bytes( $big_integer );

 $secspack = new Data::Secs2( @options );
 $secspack = new Data::Secs2( [@options] );
 $secspack = new Data::Secs2( {options} );

 ($format, $floats) = Data::SecsPack->pack_float($format, @string_integers);

 ($format, $integers) = Data::SecsPack->pack_int($format, @string_integers);

 ($format, $numbers, @strings) = Data::SecsPack->pack_num($format, @strings);

 $integer = Data::SecsPack->str2int($string)
 (\@strings, @integers) = Data::SecsPack->str2int(@strings);

 $float = Data::SecsPack->str2float($string);
 (\@strings, @floats) = Data::SecsPack->str2float(@strings);

 \@ingegers = Data::SecsPack->unpack_int($format, $integer_string); 
 \@floats   = Data::SecsPack->unpack_float($format, $float_string); 
 \@numbers  = Data::SecsPack->unpack_num($format, $number_string); 

DESCRIPTION

The subroutines in the Data::SecsPack module packs and unpacks numbers in accordance with SEMI E5-94. The E5-94 establishes the standard for communication between the equipment used to fabricate semiconductors and the host computer that controls the fabrication. The equipment in a semiconductor factory (fab) or any other fab contains every conceivable known microprocessor and operating system known to man. And there are a lot of specialize real-time embedded processors and speciallize real-time embedded operating systems in addition to the those in the PC world.

The communcication between host and equipment used packed nested list data structures that include arrays of characters, integers and floats. The standard has been in place and widely used in china, germany, korea, japan, france, italy and the most remote places on this planent for decades. The basic data structure and packed data formats have not changed for decades.

This stands in direct contradiction to common conceptions of many in the Perl community. The following quote is taken from page 761, Programming Perl third edition, discussing the pack subroutine:

"Floating-point numbers are in the native machine format only. Because of the variety of floating format and lack of a standard "network" represenation, no facility for interchange has been made. This means that packed floating-point data written on one machine may not be readable on another. That is a problem even when both machines use IEEE floating-point arithmetic, because the endian-ness of memory representation is not part of the IEEE spec."

SEMI E5-94 and their precessors do standardize the endian-ness of floating point, the packing of nested data, used in many programming languages, and much, much more. The nested data has many performance advantages over the common SQL culture of viewing and representing data. The automated fabs of the world make use of nested data not only for communication between machines but also for local processing at the host and equipment.

The endian-ness of SEMI E5-94 is the first MSB byte. Maybe this is because it makes it easy to spot numbers in a packed data structure.

Does this standard communications protocol ensure that everything goes smoothly without any glitches with this wild mixture of hardware and software talking to each other in real time? Of course not. Bytes get reverse. Data gets jumbled from point A to point B. Machine time is non-existance. Big ticket, multi-million dollar fab equipment has to work to earn its keep. And, then there is the everyday business of suiting up, with humblizing hair nets, going through air and other showers just to get in to the clean room. And make sure not to do anything that will damage a little cassette containing a million dollars worth of product. It is totally amazing that the product does get out the door.

SECSII Format

The Data::SecsPack suroutines packs and unpacks numbers in accordance with SEMI E5-94, Semiconductor Equipment Communications Standard 2 (SECS-II), avaiable from

 Semiconductor Equipment and Materials International
 805 East Middlefield Road,
 Mountain View, CA 94043-4080 USA
 (415) 964-5111
 Easylink: 62819945
 http://www.semiconductor-intl.org
 http://www.reed-electronics.com/semiconductor/
 

The format of SEMI E5-94 numbers are established by below Table 1.

               Table 1 Item Format Codes

 unpacked   binary  octal  hex   description
 ---------------------------------------------------------
 T          001001   11    0x24  Boolean
 S8         011000   30    0x60  8-byte integer (signed)
 S1         011001   31    0x62  1-byte integer (signed)
 S2         011010   32    0x64  2-byte integer (signed)
 S4         011100   34    0x70  4-byte integer (signed)
 F8         100000   40    0x80  8-byte floating
 F4         100100   44    0x90  4-byte floating
 U8         101000   50    0xA0  8-byte integer (unsigned)
 U1         101001   51    0xA4  1-byte integer (unsigned)
 U2         101010   52    0xA8  2-byte integer (unsigned)
 U4         101100   54    0xB0  4-byte integer (unsigned)

Table 1 complies to SEMI E5-94 Table 1, p.94, with an unpack text symbol and hex columns added. The hex column is the upper Most Significant Bits (MSB) 6 bits of the format code in the SEMI E5-94 item header (IH)

In accordance with SEMI E5-94 6.2.2,

  1. the Most Significat Byte (MSB) of numbers for formats S2, S4, S8, U2, U4, U8 is sent first

  2. the signed bit for formats F4 and F8 are sent first.

  3. Signed integer formats S1, S2, S4, S8 are two's complement

The memory layout for Data::SecsPack is the SEMI E5-94 "byte sent first" has the lowest memory address.

The SEMI E5-94 F4 format complies to IEEE 754-1985 float and the F8 format complies to IEEE 754-1985 double. The IEEE 754-1985 standard is available from:

 IEEE Service Center
 445 Hoe Lane,
 Piscataway, NJ 08854
  

The SEMI E5-94 F4, IEEE 754-1985 float, is 32 bits with the bits assigned follows:

 S EEE EEEE EMMM MMMM MMMM MMMM MMMM MMMM

where S = sign bit, E = 8 exponent bits M = 23 mantissa bits

The format of the float S, E, and M are as follows:

Sign of the number

The sign is one bit, 0 for positive and 1 for negative.

exponent

The exponent is 8 bits and may be positive or negative. The IEEE 754 exponent uses excess-127 format. The excess-127 format adds 127 to the exponent. The exponent is re-created by subtracting 127 from the exponent.

Magnitude of the number

The magnitude or mantissa is a 23 bit unsigned binary number where the radix is adjusted to make the magnitude fall between 1 and 2. The magnitude is stored ignoring the 1 and filling in the trailing bits until there are 23 of them.

The SEMI E5-94 F4, IEEE 754-1985 double, is 64 bits with S,E,M as follows: S = sign bit, E = 11 exponent bits M = 52 mantissa bits

The format of the float S, E, and M are as follows:

Sign of the number

The sign is one bit, 0 for positive and 1 for negative.

exponent

The exponent is 8 bits and may be positive or negative. The IEEE 754 exponent uses excess-1027 format. The excess-1027 format adds 1027 to the exponent. The exponent is re-created by subtracting 1027 from the exponent.

Magnitude of the number

The magnitude or mantissa is a 52 bit unsigned binary number where the radix is adjusted to make the magnitude fall between 1 and 2. The magnitude is stored ignoring the 1 and filling in the trailing bits until there are 52 of them.

For example, to find the IEEE 754-1985 float of -10.5

  • Convert -10.5 decimal to -1010.1 binary

  • Move the radix so magitude is between 1 and 2, -1010. binary to -1.0101 * 2^ +3

  • IEEE 754-1985 sign is 1

  • The magnitude dropping the one and filling in with 23 bits is

     01010000000000000000000
  • Add 127 to the exponent of 3 to get

     130 decimal converted to 8 bit binary 
    
     10000010
  • Combining into IEEE 754-1985 format:

     11000001001010000000000000000000
    
     1100 0001 0010 1000 0000 0000 0000 0000
    
     C128 0000 hex

SUBROUTINES

bytes2int

 $big_integer = bytes2int( @bytes );

The bytes2int subroutine counvers a @bytes binary number with the Most Significant Byte (MSB) $byte[0] to a decimal string number $big_integer using the Data::BigInt program module. As such, the only limitations on the number of binary bytes and decimal digits is the resources of the computer.

config

 $old_value = config( $option );
 $old_value = config( $option => $new_value);
 (@all_options) = config( );

The config subroutine reads and writes the default, startup options for the subroutines in the Data::Secs2 program module and package. The options, with description in the subroutine where they are used, are as follows:

 used by                                        
 subroutine    option                        default value
 ----------------------------------------------------------
               big_float_version
               big_int_version
               version

 bytes2int 

 float2binary  decimal_integer_digits          20
               extra_decimal_fraction_digits    5 

 ifloat2binary decimal_fraction_digits         25
               binary_fraction_bytes           10

 int2bytes   
 pack_float 
 pack_int 

 pack_num       nomix                          0
 
 str2float
 str2int 
 unpack_float
 unpack_int
 unpack_num

The bin_float_version bin_int_version and version configuration variables are the versions for the Math::BigFloat Math::BigInt Data::Secs2 program modules respectively.

float2binary

 ($binary_magnitude, $binary_exponent) = float2binary($magnitude, $exponent, @options); 

The ifloat2binary subroutine converts a decimal float with a base ten $magnitude and $exponent to a binary float with a base two $binary_magnitude and $binary_exponent.

The ifloat2binary assumes that the decimal point is set by ixpeonent so that there is one decimal integer digit in imagnitude The ifloat2binary produces a $binary_exponent so that the first byte of $binary_magnitude is 1 and the rest of the bytes are a base 2 fraction.

The float2binary subroutine uses the ifloat2binary for the small $exponents part and the native float routines to correct the ifloat2binary for the base ten exponent factor outside the range of the ifoat2binary subroutine.

The float2binary subroutine uses the options decimal_integer_digits, $decial_fraction_digits, extra_decimal_fraction_digits in determining the $iexponent passed to the ifloat2binary subroutine. The option decimal_integer_digits is the largest positive base ten $iexponent while smallest $ixponent is the half $decial_fraction_digits + extra_decimal_fraction_digits. The float2binary subroutine extra_decimal_fraction_digits only for negative $iexponent. The float2binary subroutine uses any base ten $exponent from $iexponent breakout to adjust the ifloat2binary subroutine results using native float arith.

ifloat2binary

 ($binary_magnitude, $binary_exponent) = ifloat2binary($imagnitude, $iexponent, @options);

The $ifloat2binary subroutine converts a decimal float with a base ten $imagnitude and $iexponent using the Math::BigInt program module to a binary float with a base two $binary_magnitude and a base two $binary_exponent. The $ifloat2binary assumes that the decimal point is set by ixpeonent so that there is one decimal integer digit in imagnitude The ifloat2binary produces a $binary_exponent so that the first byte of $binary_magnitude is 1 and the rest of the bytes are a base 2 fraction.

Since all the calculations use basic integer arith, there are practical limits on the computer resources. Basically the limit is that with a zero exponent, the decimal point is within the significant imagnitude digits. Within these limitations, the accuracy, by chosen large enough limits for the binary fraction, is perfect.

The first step of the ifloat2binary subroutine is zero out iexponent by breaking up the imagnitude into an integer part integer and fractional part fraction consist with the iexponent. The c<ifloat2binary> will add as many significant decimal zeros to the right of integer in order to zero out iexponent; likewise it will add as many decimal zeros to the left of integer to zero out exponent within the limit set by the option decimal_fraction_digits. If ifloat2binary cannot zero out iexponent without violating the decimal_fraction_digits, ifloat2binary will discontinue processing and return an undef $binary_magnitude with and error message in $binary_exponent.

This design is based on the fact that the conversion of integer decimal to binary decimal is one to one, while the conversion of fractional decimal to binary decimal is not. When converting from decimal fractions with finite digits to binary fractions repeating binary fractions of infinity size are possible, and do happen quite frequently. An unlimited repeating binary fraction will quickly use all computer resources. The binary_fraction_bytes option provides this ungraceful event by limiting the number of fractional binary bytes. The default limits of 20 decimal_fraction_digits and binary_fraction_bytes 10 bytes provides a full range of 0 - 255 for each binary byte. The ten bytes are three more bytes then are ever used in the largest F8 SEMI float format.

The the following example illustrates the method used by ifloat2binary to convert decimal fracional digits to binary fractional bytes. Convert a 6 digit decimal fraction string into a binary fraction as follows:

 N[0-999999]      
 -----------  =  
   10^6          

 byte0    byte1   byte2    256         R2
 ----- +  ----- + ----- + ----- * ------------
 256^1    256^2   256^3   256^4     10 ^ 6

Six digits was chosen so that the integer arith, using a 256 base, does not over flow 32 bit signed integer arith

 256 *   99999     =   25599744
 256 *  999999     =  255999744
 signed 32 bit max = 2147483648 / 256 = 8377608
 256 * 9999999     = 2559999744

Note with quad arith this technique would yield 16 decimal fractional digits as follows:

 256 * 9999999999999999  =  2559999999999999744
 signed 64 bit max       =  9223372036854775808 / 256 = 36028797018963868
 256 * 99999999999999999 = 25599999999999999744

 Thus, need to get quad arith running.

 Basic step

  1      256 * N[0-999999]     1                     R0[0-999744]
 --- *   ----------------  =  ---- ( byte0[0-255] + ------------ ) 
 256         10 ^ 6           256                     10^6

The results will have a range of

  1
 ---- ( 0.000000 to 255.999744)
 256 

The fractional part, R0 is a six-digit decimal. Repeating the basic step three types gives the desired results. QED.

 2nd Iteration

  1      256 * R0[0-999744]       1                   R1[0-934464]
 --- *   --------------      =  ---- ( byte1[0-255] + ------------) 
 256         10 ^ 6              256                    10^6

 3rd Iteration

  1      256 * R1[0-934464]       1                   R2[0-222784]
 --- *   --------------      =  ---- ( byte2[0-239] + ------------) 
 256         10 ^ 6              256                    10^6

Taking this out to ten bytes the first six decimal digits N[0-999999] yields bytes in the following ranges:

 byte    power      range    10^6 remainder
 ------------------------------------------ 
   0     256^-1     0-255    [0-999744]
   1     256^-2     0-255    [0-934464]
   2     256^-3     0-239    [0-222784]
   3     256^-4     0-57     [0-032704]
   4     256^-5     0-8      [0-372224]
   5     256^-6     0-95     [0-293440]
   6     256^-7     0-75     [0-120640]
   7     256^-8     0-30     [0-883840]
   8     256^-9     0-226    [0-263040]
   9     256^-10    0-67     [0-338249]

The first two binary fractional bytes have full range. The rest except for byte 9 are not very close. This makes one wonder about the accuracy loss in translating from binary fractions to decimal fractions. One wonders just why have all theses problems with not just binary and decimal factions but fractions in general. Isn't mathematics wonderful.

For example in convert from decimal to binary fractions there is no clean one to one conversion as for integers. For example, look at the below table of conversions:

 -1    -2     -3     -4     -5     binary power as a decimal   
 0.5   0.25  0.125 0.0625 0.03125  decimal power 
                                   decimal 
  0     0      0      0      0     0.00000
  0     0      0      0      1     0.03125
  0     0      0      1      1     0.0625
  0     0      1      0      0     0.125
  0     0      1      0      1     0.15625
  0     0      1      1      0     0.1875
  0     0      1      1      1     0.21875
  1     0      0      0      0     0.50000

int2bytes

 @bytes = int2bytes( $big_integer );

The int2bytes subroutine uses the Data:BigInt program module to convert an integer text string $bit_integer into a byte array, @bytes, the Most Significant Byte (MSB) being $bytes[0]. There is no limits on the size of $big_integer or @bytes except for the resources of the computer.

new

 $secspack = new Data::Secs2( @options );
 $secspack = new Data::Secs2( [@options] );
 $secspack = new Data::Secs2( {options} );

The new subroutine provides a method to set local options once for any of the other subroutines. The options may be modified at any time by $secspack-config($option => $new_value)>. Calling any of the subroutines as a $secspack method will perform that subroutine with the options saved in secspack.

pack_float

 ($format, $floats) = pack_float($format, @string_integers);

The pack_int subroutine takes an array of strings, <@string_integers>, and a float format code, as specifed in the above Item Format Code Table, and packs all the integers, decimals and floats as a float the $format in accordance with SEMI E5-94. The pack_int subroutine also accepts the format code F and format codes with out the bytes-per-element number and packs the numbers in the format using the less space. In any case, the pack_int subroutine returns the correct $format of the packed $integers.

When the pack_float encounters an error, it returns undef for $format and a description of the error as $floats.

pack_int

 ($format, $integers) = pack_int($format, @string_integers);

The pack_int subroutine takes an array of strings, <@string_integers>, and a format code, as specifed in the above Item Format Code Table and packs the integers, $integers in the $format in accordance with SEMI E5-94. The pack_int subroutine also accepts the format code I I1 I2 I8 and format codes with out the bytes-per-element number and packs the numbers in the format using the less space, with unsigned preferred over signed. In any case, the pack_int subroutine returns the correct $format of the packed $integers.

When the pack_int encounters an error, it returns undef for $format and a description of the error as $integers. All the @string_integers must be valid Perl numbers.

pack_num

 ($format, $numbers, @strings) = pack_num($format, @strings);

The pack_num subroutine takes leading numbers in @strings and packs them in the $format in accordance with SEMI E5-94. The pack_num subroutine returns the stripped @strings data naked of all leading numbers in $format.

The pack_num subroutine also accepts $format of I I1 I2 I4 F For these format codes, pack_num is extremely liberal and accepts processes all numbers consistence with the $format and packs one or more numbers in the SEMI E5-94 format that takes the least space. In this case, the return $format is changed to the SEMI E5-94 from the Item FOrmat Code Table of the packed numbers.

For the I $format, if the nomix option is set option, the pack_num subroutine will pack all leading, integers, decimals and floats as multicell float with the smallest space; otherwise, it will stop at the first decimal or float encountered and just pack the integers.

The pack_num subroutine processes @strings in two steps. In the first step, the pack_num subroutine uses str2int and/or str2float subroutines to parse the leading numbers from the @strings as follows:

 ([@strings], @integers) = str2int(@strings); 
 ([@strings], @floats) = str2float(@strings); 

In the second step, the pack_num subroutine uses pack_int and/or pacK_float to pack the parsed numbers.

str2float

 $float = str2float($string);
 (\@strings, @floats) = str2float(@strings);

The str2float subroutine, in an array context, supports converting multiple run of integers, decimals or floats in an array of strings @strings to an array of integers, decimals or floats, @floats. It keeps converting the strings, starting with the first string in @strings, continuing to the next and next until it fails an conversion. The str2int returns the stripped string data, naked of all integers, in @strings and the array of integers @integers.

In a scalar context, it parse out any type of $number in the leading $string. This is especially useful for $string that is certain to have a single number.

str2int

 $integer = str2int($string);
 (\@strings, @integers) = str2int(@strings); 

In a scalar context, the Data::SecsPack program module translates an scalar string to a scalar integer. Perl itself has a documented function, '0+$x', that converts a scalar to so that its internal storage is an integer (See p.351, 3rd Edition of Programming Perl). If it cannot perform the conversion, it leaves the integer 0. Surprising not all Perls, some Microsoft Perls in particular, may leave the internal storage as a scalar string.

The scalar str2int subroutine is basically the same except if it cannot perform the conversion to an integer, it returns an "undef" instead of a 0. Also, if the string is a decimal or floating point, it will return an undef. This makes it not only useful for forcing an integer conversion but also for testing a scalar to see if it is in fact an integer scalar. The scalar str2int is the same and supercedes C&<Data::SecsPack::str2int>. The Data::SecsPack program module superceds the Data::SecsPack program module.

The str2int subroutine, in an array context, supports converting multiple run of integers in an array of strings @strings to an array of integers, @integers. It keeps converting the strings, starting with the first string in @strings, continuing to the next and next until it fails a conversion. The str2int returns the remaining string data in @strings and the array of integers @integers.

unpack_float

 \@floats   = unpack_float($format, $float_string);

The unpack_num subroutine unpacks an array of floats $float_string packed in accordance with SEMI-E5 $format. A valid $format, in accordance with the above Item Format Code Table, is F4 F8.

The unpack_num returns a reference, \@floats, to the unpacked float array or scalar error message $error. To determine a valid return or an error, check that ref of the return exists or is 'ARRAY'.

unpack_int

 \@integers = unpack_int($format, $integer_string); 

The unpack_num subroutine unpacks an array of numbers $string_numbers packed in accordance with SEMI-E5 $format. A valid $format, in accordance with the above Item Format Code Table, is S1 S2 S4 U1 U2 U4 T.

The unpack_num returns a reference, \@integers, to the unpacked integer array or scalar error message $error. To determine a valid return or an error, check that ref of the return exists or is 'ARRAY'.

unpack_num

 \@numbers  = unpack_num($format, $number_string); 

The unpack_num subroutine unpacks an array of numbers $number_string packed in accordance with SEMI-E5 $format. A valid $format, in accordance with the above Item Format Code Table, is S1 S2 S4 U1 U2 U4 F4 F8 T. The unpack_num subroutine uses either unpack_float or unpack_int depending upon $format.

The unpack_num returns a reference, \@numbers, to the unpacked number array or scalar error message $error. To determine a valid return or an error, check that ref of the return exists or is 'ARRAY'.

REQUIREMENTS

Coming soon.

DEMONSTRATION

 #########
 # perl SecsPack.d
 ###

 ~~~~~~ Demonstration overview ~~~~~

Perl code begins with the prompt

 =>

The selected results from executing the Perl Code follow on the next lines. For example,

 => 2 + 2
 4

 ~~~~~~ The demonstration follows ~~~~~

 =>     use File::Package;
 =>     my $fp = 'File::Package';

 =>     my $uut = 'Data::SecsPack';
 =>     my $loaded;

 =>     my ($result,@result);

 =>     #########
 =>     # Subroutines to test that actual values are within
 =>     # and expected tolerance of the expected value
 =>     #
 =>     sub tolerance
 =>     {
 =>         my ($actual,$expected) = @_;
 =>         2 * ($expected - $actual) / ($expected + $actual);
 =>     }

 =>     sub pass_fail_tolerance
 =>     {   my ($actual,$expected) = @_;
 =>          (-$expected < $actual) && ($actual < $expected) ? 1 : 0;
 =>     }

 =>     my $tolerance_result;
 =>     my $float_tolerance = 1E-10;

 => ##################
 => # UUT Loaded
 => # 
 => ###

 =>    my $errors = $fp->load_package($uut, 
 =>        qw(bytes2int float2binary 
 =>           ifloat2binary int2bytes   
 =>           pack_float pack_int pack_num  
 =>           str2float str2int 
 =>           unpack_float unpack_int unpack_num) );
 => $errors
 ''

 => ##################
 => # str2int(\'033\')
 => # 
 => ###

 => $result = $uut->str2int('033')
 '27'

 => ##################
 => # str2int(\'0xFF\')
 => # 
 => ###

 => $result = $uut->str2int('0xFF')
 '255'

 => ##################
 => # str2int(\'0b1010\')
 => # 
 => ###

 => $result = $uut->str2int('0b1010')
 '10'

 => ##################
 => # str2int(\'255\')
 => # 
 => ###

 => $result = $uut->str2int('255')
 '255'

 => ##################
 => # str2int(\'hello\')
 => # 
 => ###

 => $result = $uut->str2int('hello')
 undef

 => ##################
 => # str2int(' 78 45 25', ' 512E4 1024 hello world') \@numbers
 => # 
 => ###

 => my ($strings, @numbers) = str2int(' 78 45 25', ' 512E4 1024 hello world')
 => [@numbers]
 [
           '78',
           '45',
           '25'
         ]

 => ##################
 => # str2int(' 78 45 25', ' 512E4 1024 hello world') \@strings
 => # 
 => ###

 => join( ' ', @$strings)
 '512E4 1024 hello world'

 => ##################
 => # str2float(' 78 -2.4E-6 0.25', ' 512E4 hello world') numbers
 => # 
 => ###

 => ($strings, @numbers) = str2float(' 78 -2.4E-6 0.0025', ' 512E4 hello world')
 => [@numbers]
 [
           [
             '78',
             '1'
           ],
           [
             '-24',
             '-6'
           ],
           [
             '025',
             -3
           ],
           [
             '512',
             '6'
           ]
         ]

 => ##################
 => # str2float(' 78 -2.4E-6 0.25', ' 512E4 hello world') \@strings
 => # 
 => ###

 => ($strings, @numbers) = str2float(' 78 -2.4E-6 0.0025', ' 512E4 hello world')
 => join( ' ', @$strings)
 'hello world'

 =>      my @test_strings = ('78 45 25', '512 1024 100000 hello world');
 =>      my $test_string_text = join ' ',@test_strings;
 =>      my $test_format = 'I';
 =>      my $expected_format = 'U4';
 =>      my $expected_numbers = '0000004e0000002d000000190000020000000400000186a0';
 =>      my $expected_strings = ['hello world'];
 =>      my $expected_unpack = [78, 45, 25, 512, 1024, 100000];

 =>      my ($format, $numbers, @strings) = pack_num('I',@test_strings);

 => ##################
 => # pack_num($test_format, $test_string_text) format
 => # 
 => ###

 => $format
 'U4'

 => ##################
 => # pack_num($test_format, $test_string_text) numbers
 => # 
 => ###

 => unpack('H*',$numbers)
 '0000004e0000002d000000190000020000000400000186a0'

 => ##################
 => # pack_num($test_format, $test_string_text) \@strings
 => # 
 => ###

 => [@strings]
 [
           'hello world'
         ]

 => ##################
 => # unpack_num($expected_format, $test_string_text) error check
 => # 
 => ###

 => ref(my $unpack_numbers = unpack_num($expected_format,$numbers))
 'ARRAY'

 => ##################
 => # unpack_num($expected_format, $test_string_text) numbers
 => # 
 => ###

 => $unpack_numbers
 [
           '78',
           '45',
           '25',
           '512',
           '1024',
           '100000'
         ]

 =>  
 =>      @test_strings = ('78 4.5 .25', '6.45E10 hello world');
 =>      $test_string_text = join ' ',@test_strings;
 =>      $test_format = 'I';
 =>      $expected_format = 'F8';
 =>      $expected_numbers = '405380000000000040120000000000003fd0000000000000422e08ffca000000';
 =>      $expected_strings = ['hello world'];
 =>      my @expected_unpack = (78, 4.5, 0.25,6.45E10);

 =>      ($format, $numbers, @strings) = pack_num('I',@test_strings);

 => ##################
 => # pack_num($test_format, $test_string_text) format
 => # 
 => ###

 => $format
 'F8'

 => ##################
 => # pack_num($test_format, $test_string_text) numbers
 => # 
 => ###

 => unpack('H*',$numbers)
 '405380000000000040120000000000003fd0000000000000422e08ffca000000'

 => ##################
 => # pack_num($test_format, $test_string_text) \@strings
 => # 
 => ###

 => [@strings]
 [
           'hello world'
         ]

 => ##################
 => # unpack_num($expected_format, $test_string_text) error check
 => # 
 => ###

 => ref($unpack_numbers = unpack_num($expected_format,$numbers))
 'ARRAY'

 => $unpack_numbers
 [
           '7800000000000017486e-17',
           '4500000000000006245e-18',
           '25e-2',
           '64500000000000376452e-9'
         ]

QUALITY ASSURANCE

Test Report

  => perl SecsPack.t
 
 1..23
 # Running under perl version 5.006001 for MSWin32
 # Win32::BuildNumber 635
 # Current time local: Sat Apr 24 01:43:15 2004
 # Current time GMT:   Sat Apr 24 05:43:15 2004
 # Using Test.pm version 1.24
 # Test::Tech    : 1.2
 # Data::Secs2   : 1.17
 # Data::SecsPack: 0.03
 # =cut 
 ok 1 - UUT Loaded 
 ok 2 - str2int('033') 
 ok 3 - str2int('0xFF') 
 ok 4 - str2int('0b1010') 
 ok 5 - str2int('255') 
 ok 6 - str2int('hello') 
 ok 7 - str2int(' 78 45 25', ' 512E4 1024 hello world') @numbers 
 ok 8 - str2int(' 78 45 25', ' 512E4 1024 hello world') @strings 
 ok 9 - str2float(' 78 -2.4E-6 0.25', ' 512E4 hello world') numbers 
 ok 10 - str2float(' 78 -2.4E-6 0.25', ' 512E4 hello world') @strings 
 ok 11 - pack_num(I, 78 45 25 512 1024 100000 hello world) format 
 ok 12 - pack_num(I, 78 45 25 512 1024 100000 hello world) numbers 
 ok 13 - pack_num(I, 78 45 25 512 1024 100000 hello world) @strings 
 ok 14 - unpack_num(U4, 78 45 25 512 1024 100000 hello world) error check 
 ok 15 - unpack_num(U4, 78 45 25 512 1024 100000 hello world) numbers 
 ok 16 - pack_num(I, 78 4.5 .25 6.45E10 hello world) format 
 ok 17 - pack_num(I, 78 4.5 .25 6.45E10 hello world) numbers 
 ok 18 - pack_num(I, 78 4.5 .25 6.45E10 hello world) @strings 
 ok 19 - unpack_num(F8, 78 4.5 .25 6.45E10 hello world) error check 
 ok 20 - unpack_num(F8, 78 4.5 .25 6.45E10 hello world) float 0 
 ok 21 - unpack_num(F8, 78 4.5 .25 6.45E10 hello world) float 1 
 ok 22 - unpack_num(F8, 78 4.5 .25 6.45E10 hello world) float 2 
 ok 23 - unpack_num(F8, 78 4.5 .25 6.45E10 hello world) float 3 
 # Passed : 23/23 100%
 

Other Tests

The test script SecsPackStress.t provides a more thorough test and is provided in the distribution package along with its demo script companion SecsPackStress.d.

The Software Test Description (STD) for SecsPackStress is SecsPackStress.pm also in the distribution package. The installation runs both SecsPack.t and SecsPackStress.t.

Test Software

The module "t::Data::SecsPack" is the Software Test Description(STD) module for the "Data::SecsPack". module.

To generate all the test output files, run the generated test script, run the demonstration script and include it results in the "Data::SecsPack" POD, execute the following in any directory:

 tmake -test_verbose -replace -run  -pm=t::Data::SecsPack

Note that tmake.pl must be in the execution path $ENV{PATH} and the "t" directory containing "t::Data::SecsPack" on the same level as the "lib" directory that contains the "Data::SecsPack" module.

NOTES

AUTHOR

The holder of the copyright and maintainer is

<support@SoftwareDiamonds.com>

Copyrighted (c) 2002 Software Diamonds

All Rights Reserved

BINDING REQUIREMENTS NOTICE

Binding requirements are indexed with the pharse 'shall[dd]' where dd is an unique number for each header section. This conforms to standard federal government practices, 490A ("3.2.3.6" in STD490A). In accordance with the License, Software Diamonds is not liable for any requirement, binding or otherwise.

LICENSE

Software Diamonds permits the redistribution and use in source and binary forms, with or without modification, provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

SOFTWARE DIAMONDS, http::www.softwarediamonds.com, PROVIDES THIS SOFTWARE 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWARE DIAMONDS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING USE OF THIS SOFTWARE, EVEN IF ADVISED OF NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE POSSIBILITY OF SUCH DAMAGE.

SEE_ALSO:

Math::BigInt
Math::BigFloat
Data::Secs2