Skip to content

Commit 6228571

Browse files
authored
od: make float formats accessible with -t (#930)
* Support arguments "-t f4" and "-t f8", which are already exposed as options -f and -F respectively * In future, od can support multiple formats at once, e.g. "-t f4f8", but for now only one format is allowed
1 parent 1b358e8 commit 6228571

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

bin/od

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ elsif ($opt_e || $opt_F) {
132132
$fmt = \&float8;
133133
}
134134
elsif ($opt_f) {
135-
$fmt = \&float;
135+
$fmt = \&float4;
136136
}
137137
elsif ($opt_H || $opt_X) {
138138
$fmt = \&hex4;
@@ -189,6 +189,10 @@ if (defined $opt_t) {
189189
$fmt = \&udecimal4;
190190
} elsif ($opt_t eq 'u8') {
191191
$fmt = \&udecimal8;
192+
} elsif ($opt_t eq 'f4') {
193+
$fmt = \&float4;
194+
} elsif ($opt_t eq 'f8') {
195+
$fmt = \&float8;
192196
} elsif ($opt_t eq 'a') {
193197
$fmt = \&char7bit;
194198
} elsif ($opt_t eq 'c') {
@@ -365,7 +369,7 @@ sub udecimal2 {
365369
$strfmt = '%5u ' x (scalar @arr);
366370
}
367371

368-
sub float {
372+
sub float4 {
369373
@arr = unpack 'f*', $data . zeropad(length($data), 4);
370374
$strfmt = '%15.7e ' x (scalar @arr);
371375
}
@@ -569,6 +573,8 @@ Select output format as one of the following:
569573
x2 2-byte unsigned hexadecimal
570574
x4 4-byte unsigned hexadecimal
571575
x8 8-byte unsigned hexadecimal
576+
f4 4-byte floating point. Same as -f
577+
f8 8-byte floating point. Same as -F
572578
573579
This option overrides other formatting options.
574580

0 commit comments

Comments
 (0)