diff --git a/c/todo.txt b/c/todo.txt index df07c211e..db9fd83eb 100644 --- a/c/todo.txt +++ b/c/todo.txt @@ -9,6 +9,7 @@ BUGFIXES TOP-OF-LIST SUMMARY ! entirely rework null-data section @ mld; manify?/mldify! mlr --print-type-arithmetic-info; typeof + -> merge absent & uninit ?!? ! valgrinds ! do absent-identity for logical, bitwise, and exp? UTs for all regardless of what changes/doesn't. * doc warn: the same implicit-identity feature that makes oosvars usable (emph in nested maps) makes it confusing for diff --git a/doc/content-for-reference.html b/doc/content-for-reference.html index 4913ac076..8f123527a 100644 --- a/doc/content-for-reference.html +++ b/doc/content-for-reference.html @@ -83,85 +83,6 @@ POKI_RUN_COMMAND{{mlr --help}}HERE POKI_RUN_COMMAND{{mlr sort --help}}HERE - -

Data types

- -

Miller’s input and output are all string-oriented: there is (as of -August 2015 anyway) no support for binary record packing. In this sense, -everything is a string in and out of Miller. During processing, field names -are always strings, even if they have names like "3"; field values are usually -strings. Field values’ ability to be interpreted as a non-string type -only has meaning when comparison or function operations are done on them. And -it is an error condition if Miller encounters non-numeric (or otherwise -mistyped) data in a field in which it has been asked to do numeric (or -otherwise type-specific) operations. - -

Field values are treated as numeric for the following: -

- -

For mlr put and mlr filter: - -

- - -

Null data

- -

One of Miller’s key features is its support for heterogeneous data. -Accordingly, if you try to sort on field hostname when not all records in the data -stream have a field named hostname, it is not an error (although you could -pre-filter the data stream using mlr having-fields --at-least hostname then sort ...). -Rather, records lacking one or more sort keys are simply output contiguously by mlr sort. - -

Field values may also be null by being -specified with present key but empty value: e.g. sending x=,y=2 to mlr put '$z=$x+$y'. - -

-Rules for null-handling: -

-

I/O options

@@ -1294,146 +1215,114 @@ pipeline stage. POKI_RUN_COMMAND{{mlr --help-all-functions}}HERE -

Operator precedence

+

Data types

-

Operators are listed in order of decreasing precedence, highest first. +

Miller’s input and output are all string-oriented: there is (as of +August 2015 anyway) no support for binary record packing. In this sense, +everything is a string in and out of Miller. During processing, field names +are always strings, even if they have names like "3"; field values are usually +strings. Field values’ ability to be interpreted as a non-string type +only has meaning when comparison or function operations are done on them. And +it is an error condition if Miller encounters non-numeric (or otherwise +mistyped) data in a field in which it has been asked to do numeric (or +otherwise type-specific) operations. -

-

-
-Operators              Associativity
----------              -------------
-()                     left to right
-**                     right to left
-! ~ unary+ unary- &    right to left
-binary* / // %         left to right
-binary+ binary- .      left to right
-<< >>                  left to right
-&                      left to right
-^                      left to right
-|                      left to right
-< <= > >=              left to right
-== != =~ !=~           left to right
-&&                     left to right
-^^                     left to right
-||                     left to right
-? :                    right to left
-=                      N/A for Miller (there is no $a=$b=$c)
-
-
-

+

Field values are treated as numeric for the following: +

- -

Operator and function semantics

+

For mlr put and mlr filter:

-

Arithmetic

+

Null data

-

Input scanning

+

One of Miller’s key features is its support for heterogeneous data. +Accordingly, if you try to sort on field hostname when not all records in the data +stream have a field named hostname, it is not an error (although you could +pre-filter the data stream using mlr having-fields --at-least hostname then sort ...). +Rather, records lacking one or more sort keys are simply output contiguously by mlr sort. -

Numbers in Miller are double-precision float or 64-bit signed integers. -Anything scannable as int, e.g 123 or 0xabcd, is treated as -an integer; otherwise, input scannable as float (4.56 or 8e9) -is treated as float; everything else is a string. +

Miller has three kinds of null data: -

If you want all numbers to be treated as floats, then you may use -float() in your filter/put expressions (e.g. replacing $c = $a * -$b with $c = float($a) * float($b)) — or, more simply, use -mlr filter -F and mlr put -F which forces all numeric input, -whether from expression literals or field values, to float. Likewise mlr -stats1 -F and mlr step -F force integerable accumulators (such as -count) to be done in floating-point. +

-

The short of it is that Miller does this transparently for you so you -needn’t think about it. + -

-
-   64-bit integer     64-bit integer     Casted to double           Back to 64-bit
-       in hex           in decimal                                    integer
-0x7ffffffffffff9ff 9223372036854774271 9223372036854773760.000000 0x7ffffffffffff800
-0x7ffffffffffffa00 9223372036854774272 9223372036854773760.000000 0x7ffffffffffff800
-0x7ffffffffffffbff 9223372036854774783 9223372036854774784.000000 0x7ffffffffffffc00
-0x7ffffffffffffc00 9223372036854774784 9223372036854774784.000000 0x7ffffffffffffc00
-0x7ffffffffffffdff 9223372036854775295 9223372036854774784.000000 0x7ffffffffffffc00
-0x7ffffffffffffe00 9223372036854775296 9223372036854775808.000000 0x8000000000000000
-0x7ffffffffffffffe 9223372036854775806 9223372036854775808.000000 0x8000000000000000
-0x7fffffffffffffff 9223372036854775807 9223372036854775808.000000 0x8000000000000000
-
-
+

+Rules for null-handling: +

-

That is, one cannot check an integer product to see if it is precisely -greater than 263-1 or less than -263 using either integer -arithmetic (it may have already overflowed) or using double-precision (due to -granularity). Instead Miller checks for overflow in 64-bit integer -multiplication by seeing whether the absolute value of the double-precision -product exceeds the largest representable IEEE double less than 263, -which we see from the listing above is 9223372036854774784. (An alternative -would be to do all integer multiplies using handcrafted multi-word 128-bit -arithmetic. This approach is not taken.) +

String literals

@@ -1574,3 +1463,145 @@ mlr filter '$a =~ "(..)_(....)' \0 is the entire match string; \15 is treated as \1 followed by an unrelated 5. + + +

Operator precedence

+ +

Operators are listed in order of decreasing precedence, highest first. + +

+

+
+Operators              Associativity
+---------              -------------
+()                     left to right
+**                     right to left
+! ~ unary+ unary- &    right to left
+binary* / // %         left to right
+binary+ binary- .      left to right
+<< >>                  left to right
+&                      left to right
+^                      left to right
+|                      left to right
+< <= > >=              left to right
+== != =~ !=~           left to right
+&&                     left to right
+^^                     left to right
+||                     left to right
+? :                    right to left
+=                      N/A for Miller (there is no $a=$b=$c)
+
+
+

+ + +

Operator and function semantics

+ + + + +

Arithmetic

+ +

Input scanning

+ +

Numbers in Miller are double-precision float or 64-bit signed integers. +Anything scannable as int, e.g 123 or 0xabcd, is treated as +an integer; otherwise, input scannable as float (4.56 or 8e9) +is treated as float; everything else is a string. + +

If you want all numbers to be treated as floats, then you may use +float() in your filter/put expressions (e.g. replacing $c = $a * +$b with $c = float($a) * float($b)) — or, more simply, use +mlr filter -F and mlr put -F which forces all numeric input, +whether from expression literals or field values, to float. Likewise mlr +stats1 -F and mlr step -F force integerable accumulators (such as +count) to be done in floating-point. + +

Conversion by math routines

+ +

For most math functions, integers are cast to float on input, and produce +float output: e.g. exp(0) = 1.0 rather than 1. The +following, however, produce integer output if their inputs are integers: ++ - * / // % abs +ceil floor max min round +roundm sgn. As well, stats1 -a min, stats1 -a +max, stats1 -a sum, step -a delta, and step -a +rsum produce integer output if their inputs are integers. + +

Conversion by arithmetic operators

+ +

The sum, difference, and product of integers is again integer, except for +when that would overflow a 64-bit integer at which point Miller converts the +result to float. + +

The short of it is that Miller does this transparently for you so you +needn’t think about it. + +

Implementation details of this, for the interested: integer adds and +subtracts overflow by at most one bit so it suffices to check sign-changes. +Thus, Miller allows you to add and subtract arbitrary 64-bit signed integers, +converting only to float precisely when the result is less than -263 +or greater than 263-1. Multiplies, on the other hand, can overflow +by a word size and a sign-change technique does not suffice to detect overflow. +Instead Miller tests whether the floating-point product exceeds the +representable integer range. Now, 64-bit integers have 64-bit precision while +IEEE-doubles have only 52-bit mantissas — so, there are 53 bits including +implicit leading one. The following experiment explicitly demonstrates the +resolution at this range: + +

+
+   64-bit integer     64-bit integer     Casted to double           Back to 64-bit
+       in hex           in decimal                                    integer
+0x7ffffffffffff9ff 9223372036854774271 9223372036854773760.000000 0x7ffffffffffff800
+0x7ffffffffffffa00 9223372036854774272 9223372036854773760.000000 0x7ffffffffffff800
+0x7ffffffffffffbff 9223372036854774783 9223372036854774784.000000 0x7ffffffffffffc00
+0x7ffffffffffffc00 9223372036854774784 9223372036854774784.000000 0x7ffffffffffffc00
+0x7ffffffffffffdff 9223372036854775295 9223372036854774784.000000 0x7ffffffffffffc00
+0x7ffffffffffffe00 9223372036854775296 9223372036854775808.000000 0x8000000000000000
+0x7ffffffffffffffe 9223372036854775806 9223372036854775808.000000 0x8000000000000000
+0x7fffffffffffffff 9223372036854775807 9223372036854775808.000000 0x8000000000000000
+
+
+ +

That is, one cannot check an integer product to see if it is precisely +greater than 263-1 or less than -263 using either integer +arithmetic (it may have already overflowed) or using double-precision (due to +granularity). Instead Miller checks for overflow in 64-bit integer +multiplication by seeing whether the absolute value of the double-precision +product exceeds the largest representable IEEE double less than 263, +which we see from the listing above is 9223372036854774784. (An alternative +would be to do all integer multiplies using handcrafted multi-word 128-bit +arithmetic. This approach is not taken.) + +

Pythonic division

+ +

Division and remainder are + +pythonic: +

diff --git a/doc/data/sort-null.dat b/doc/data/sort-null.dat index 0fc8f9934..e5072761b 100644 --- a/doc/data/sort-null.dat +++ b/doc/data/sort-null.dat @@ -1,4 +1,5 @@ a=3,b=2 a=1,b=8 a=,b=4 +x=9,b=10 a=5,b=7 diff --git a/doc/mlr.1 b/doc/mlr.1 index a5f1cdc82..1163b2d03 100644 --- a/doc/mlr.1 +++ b/doc/mlr.1 @@ -2,12 +2,12 @@ .\" Title: mlr .\" Author: [see the "AUTHOR" section] .\" Generator: ./mkman.rb -.\" Date: 2016-04-12 +.\" Date: 2016-04-13 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" -.TH "MILLER" "1" "2016-04-12" "\ \&" "\ \&" +.TH "MILLER" "1" "2016-04-13" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Portability definitions .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/reference.html b/doc/reference.html index 199297a38..968ff4223 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -141,8 +141,6 @@ Miller commands were run with pretty-print-tabular output format.
Contents:
• Command overview
• On-line help
-• Data types
-• Null data
• I/O options
    • Formats
    • Compression
@@ -200,6 +198,11 @@ Miller commands were run with pretty-print-tabular output format.     • uniq
• then-chaining
• Functions for filter and put
+• Data types
+• Null data
+• String literals
+• Regular expressions
+    • Regex captures
• Operator precedence
• Operator and function semantics
• Arithmetic
@@ -207,9 +210,6 @@ Miller commands were run with pretty-print-tabular output format.     • Conversion by math routines
    • Conversion by arithmetic operators
    • Pythonic division
-• String literals
-• Regular expressions
-    • Regex captures

@@ -553,146 +553,6 @@ which is the same as:

- -

Data types

- -

Miller’s input and output are all string-oriented: there is (as of -August 2015 anyway) no support for binary record packing. In this sense, -everything is a string in and out of Miller. During processing, field names -are always strings, even if they have names like "3"; field values are usually -strings. Field values’ ability to be interpreted as a non-string type -only has meaning when comparison or function operations are done on them. And -it is an error condition if Miller encounters non-numeric (or otherwise -mistyped) data in a field in which it has been asked to do numeric (or -otherwise type-specific) operations. - -

Field values are treated as numeric for the following: -

- -

For mlr put and mlr filter: - -

- - -

Null data

- -

One of Miller’s key features is its support for heterogeneous data. -Accordingly, if you try to sort on field hostname when not all records in the data -stream have a field named hostname, it is not an error (although you could -pre-filter the data stream using mlr having-fields --at-least hostname then sort ...). -Rather, records lacking one or more sort keys are simply output contiguously by mlr sort. - -

Field values may also be null by being -specified with present key but empty value: e.g. sending x=,y=2 to mlr put '$z=$x+$y'. - -

-Rules for null-handling: -

-

I/O options

@@ -4845,146 +4705,175 @@ along with the mathematical constants PI and E.

-

Operator precedence

+

Data types

-

Operators are listed in order of decreasing precedence, highest first. +

Miller’s input and output are all string-oriented: there is (as of +August 2015 anyway) no support for binary record packing. In this sense, +everything is a string in and out of Miller. During processing, field names +are always strings, even if they have names like "3"; field values are usually +strings. Field values’ ability to be interpreted as a non-string type +only has meaning when comparison or function operations are done on them. And +it is an error condition if Miller encounters non-numeric (or otherwise +mistyped) data in a field in which it has been asked to do numeric (or +otherwise type-specific) operations. -

-

-
-Operators              Associativity
----------              -------------
-()                     left to right
-**                     right to left
-! ~ unary+ unary- &    right to left
-binary* / // %         left to right
-binary+ binary- .      left to right
-<< >>                  left to right
-&                      left to right
-^                      left to right
-|                      left to right
-< <= > >=              left to right
-== != =~ !=~           left to right
-&&                     left to right
-^^                     left to right
-||                     left to right
-? :                    right to left
-=                      N/A for Miller (there is no $a=$b=$c)
-
-
-

+

Field values are treated as numeric for the following: +

- -

Operator and function semantics

+

For mlr put and mlr filter:

-

Arithmetic

+

Null data

-

Input scanning

+

One of Miller’s key features is its support for heterogeneous data. +Accordingly, if you try to sort on field hostname when not all records in the data +stream have a field named hostname, it is not an error (although you could +pre-filter the data stream using mlr having-fields --at-least hostname then sort ...). +Rather, records lacking one or more sort keys are simply output contiguously by mlr sort. -

Numbers in Miller are double-precision float or 64-bit signed integers. -Anything scannable as int, e.g 123 or 0xabcd, is treated as -an integer; otherwise, input scannable as float (4.56 or 8e9) -is treated as float; everything else is a string. +

Miller has three kinds of null data: -

If you want all numbers to be treated as floats, then you may use -float() in your filter/put expressions (e.g. replacing $c = $a * -$b with $c = float($a) * float($b)) — or, more simply, use -mlr filter -F and mlr put -F which forces all numeric input, -whether from expression literals or field values, to float. Likewise mlr -stats1 -F and mlr step -F force integerable accumulators (such as -count) to be done in floating-point. +

-

The short of it is that Miller does this transparently for you so you -needn’t think about it. + -

+

+Rules for null-handling: +

-

That is, one cannot check an integer product to see if it is precisely -greater than 263-1 or less than -263 using either integer -arithmetic (it may have already overflowed) or using double-precision (due to -granularity). Instead Miller checks for overflow in 64-bit integer -multiplication by seeing whether the absolute value of the double-precision -product exceeds the largest representable IEEE double less than 263, -which we see from the listing above is 9223372036854774784. (An alternative -would be to do all integer multiplies using handcrafted multi-word 128-bit -arithmetic. This approach is not taken.) +

String literals

@@ -5142,6 +5031,148 @@ mlr filter '$a =~ "(..)_(....)' \0 is the entire match string; \15 is treated as \1 followed by an unrelated 5. + + +

Operator precedence

+ +

Operators are listed in order of decreasing precedence, highest first. + +

+

+
+Operators              Associativity
+---------              -------------
+()                     left to right
+**                     right to left
+! ~ unary+ unary- &    right to left
+binary* / // %         left to right
+binary+ binary- .      left to right
+<< >>                  left to right
+&                      left to right
+^                      left to right
+|                      left to right
+< <= > >=              left to right
+== != =~ !=~           left to right
+&&                     left to right
+^^                     left to right
+||                     left to right
+? :                    right to left
+=                      N/A for Miller (there is no $a=$b=$c)
+
+
+

+ + +

Operator and function semantics

+ + + + +

Arithmetic

+ +

Input scanning

+ +

Numbers in Miller are double-precision float or 64-bit signed integers. +Anything scannable as int, e.g 123 or 0xabcd, is treated as +an integer; otherwise, input scannable as float (4.56 or 8e9) +is treated as float; everything else is a string. + +

If you want all numbers to be treated as floats, then you may use +float() in your filter/put expressions (e.g. replacing $c = $a * +$b with $c = float($a) * float($b)) — or, more simply, use +mlr filter -F and mlr put -F which forces all numeric input, +whether from expression literals or field values, to float. Likewise mlr +stats1 -F and mlr step -F force integerable accumulators (such as +count) to be done in floating-point. + +

Conversion by math routines

+ +

For most math functions, integers are cast to float on input, and produce +float output: e.g. exp(0) = 1.0 rather than 1. The +following, however, produce integer output if their inputs are integers: ++ - * / // % abs +ceil floor max min round +roundm sgn. As well, stats1 -a min, stats1 -a +max, stats1 -a sum, step -a delta, and step -a +rsum produce integer output if their inputs are integers. + +

Conversion by arithmetic operators

+ +

The sum, difference, and product of integers is again integer, except for +when that would overflow a 64-bit integer at which point Miller converts the +result to float. + +

The short of it is that Miller does this transparently for you so you +needn’t think about it. + +

Implementation details of this, for the interested: integer adds and +subtracts overflow by at most one bit so it suffices to check sign-changes. +Thus, Miller allows you to add and subtract arbitrary 64-bit signed integers, +converting only to float precisely when the result is less than -263 +or greater than 263-1. Multiplies, on the other hand, can overflow +by a word size and a sign-change technique does not suffice to detect overflow. +Instead Miller tests whether the floating-point product exceeds the +representable integer range. Now, 64-bit integers have 64-bit precision while +IEEE-doubles have only 52-bit mantissas — so, there are 53 bits including +implicit leading one. The following experiment explicitly demonstrates the +resolution at this range: + +

+
+   64-bit integer     64-bit integer     Casted to double           Back to 64-bit
+       in hex           in decimal                                    integer
+0x7ffffffffffff9ff 9223372036854774271 9223372036854773760.000000 0x7ffffffffffff800
+0x7ffffffffffffa00 9223372036854774272 9223372036854773760.000000 0x7ffffffffffff800
+0x7ffffffffffffbff 9223372036854774783 9223372036854774784.000000 0x7ffffffffffffc00
+0x7ffffffffffffc00 9223372036854774784 9223372036854774784.000000 0x7ffffffffffffc00
+0x7ffffffffffffdff 9223372036854775295 9223372036854774784.000000 0x7ffffffffffffc00
+0x7ffffffffffffe00 9223372036854775296 9223372036854775808.000000 0x8000000000000000
+0x7ffffffffffffffe 9223372036854775806 9223372036854775808.000000 0x8000000000000000
+0x7fffffffffffffff 9223372036854775807 9223372036854775808.000000 0x8000000000000000
+
+
+ +

That is, one cannot check an integer product to see if it is precisely +greater than 263-1 or less than -263 using either integer +arithmetic (it may have already overflowed) or using double-precision (due to +granularity). Instead Miller checks for overflow in 64-bit integer +multiplication by seeing whether the absolute value of the double-precision +product exceeds the largest representable IEEE double less than 263, +which we see from the listing above is 9223372036854774784. (An alternative +would be to do all integer multiplies using handcrafted multi-word 128-bit +arithmetic. This approach is not taken.) + +

Pythonic division

+ +

Division and remainder are + +pythonic: +