topic How to get stats command to calculate with precision for numbers in scientific notation? in Splunk Search
https://community.splunk.com/t5/Splunk-Search/How-to-get-stats-command-to-calculate-with-precision-for-numbers/m-p/178150#M51230
<P>I have found that the stats command's output doesn't use scientific notation. This means that if I need to calculate some statistics on a set of very small numbers then stats just reports 0.00000.</P>
<P>You can see the effect with this search:</P>
<PRE><CODE>| stats count | eval small="1.23456e-306" | stats min(small)
</CODE></PRE>
<P>It will always return 0.00000.</P>
<P>Is there a way to have the stats command in the above search keep the precision and return 1.23456e-306?</P>
<P>(I know in this example the stats command is pointless because there's only one value, but the real case is that I have many events containing very small numbers and I want to calculate various statistics of the data set without all the small numbers getting changed to 0.) </P>Mon, 11 Aug 2014 16:45:54 GMTdmr1952014-08-11T16:45:54ZHow to get stats command to calculate with precision for numbers in scientific notation?
https://community.splunk.com/t5/Splunk-Search/How-to-get-stats-command-to-calculate-with-precision-for-numbers/m-p/178150#M51230
<P>I have found that the stats command's output doesn't use scientific notation. This means that if I need to calculate some statistics on a set of very small numbers then stats just reports 0.00000.</P>
<P>You can see the effect with this search:</P>
<PRE><CODE>| stats count | eval small="1.23456e-306" | stats min(small)
</CODE></PRE>
<P>It will always return 0.00000.</P>
<P>Is there a way to have the stats command in the above search keep the precision and return 1.23456e-306?</P>
<P>(I know in this example the stats command is pointless because there's only one value, but the real case is that I have many events containing very small numbers and I want to calculate various statistics of the data set without all the small numbers getting changed to 0.) </P>Mon, 11 Aug 2014 16:45:54 GMThttps://community.splunk.com/t5/Splunk-Search/How-to-get-stats-command-to-calculate-with-precision-for-numbers/m-p/178150#M51230dmr1952014-08-11T16:45:54ZRe: How to get stats command to calculate with precision for numbers in scientific notation?
https://community.splunk.com/t5/Splunk-Search/How-to-get-stats-command-to-calculate-with-precision-for-numbers/m-p/178151#M51231
<P>Try something like this</P>
<PRE><CODE>| stats count | eval small="1.23456e-30" | eval small=small*1 | stats min(small)
</CODE></PRE>
<P>PS: The example value that you gave little too small so changed to little big number.</P>Mon, 11 Aug 2014 17:38:54 GMThttps://community.splunk.com/t5/Splunk-Search/How-to-get-stats-command-to-calculate-with-precision-for-numbers/m-p/178151#M51231somesoni22014-08-11T17:38:54ZRe: How to get stats command to calculate with precision for numbers in scientific notation?
https://community.splunk.com/t5/Splunk-Search/How-to-get-stats-command-to-calculate-with-precision-for-numbers/m-p/178152#M51232
<P>It seems like 125 digits to the right of the decimal point is the most that's possible. So:</P>
<P>| stats count | eval small="1.23456e-125" | eval small=small*1 | stats min(small)</P>
<P>goes to:</P>
<P>0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001</P>
<P>and:</P>
<P>| stats count | eval small="1.23456e-126" | eval small=small*1 | stats min(small)</P>
<P>loses all precision and prints 0.</P>
<P>This is a shame as the smallest double precision floating point number is 2.2e-308. But with I'm better off than I was originally, so thanks for the answer!</P>Tue, 12 Aug 2014 08:38:32 GMThttps://community.splunk.com/t5/Splunk-Search/How-to-get-stats-command-to-calculate-with-precision-for-numbers/m-p/178152#M51232dmr1952014-08-12T08:38:32ZRe: How to get stats command to calculate with precision for numbers in scientific notation?
https://community.splunk.com/t5/Splunk-Search/How-to-get-stats-command-to-calculate-with-precision-for-numbers/m-p/178153#M51233
<P>Another interesting thing is that eval can handle the full double precision accuracy, for example:</P>
<P>| stats count | eval small="1.23456e-303" | eval small=small*1</P>
<P>prints small with 308 digits to the right of the decimal point.</P>
<P>So it seems like it's the stats command that's limited to 125 decimal places.</P>Tue, 12 Aug 2014 09:06:13 GMThttps://community.splunk.com/t5/Splunk-Search/How-to-get-stats-command-to-calculate-with-precision-for-numbers/m-p/178153#M51233dmr1952014-08-12T09:06:13ZRe: How to get stats command to calculate with precision for numbers in scientific notation?
https://community.splunk.com/t5/Splunk-Search/How-to-get-stats-command-to-calculate-with-precision-for-numbers/m-p/178154#M51234
<P>A possibility for getting around the loss of precision in stats is to take logarithms before the stats command and then convert back afterwards. This works quite well:</P>
<PRE><CODE>| stats count | eval small="1.23456e-304" | eval lnsmall=ln(small) | stats min(lnsmall) as minlnsmall | eval minsmall=if(minlnsmall<-702.0, 0, exp(minlnsmall*1.0))
</CODE></PRE>
<P>The check for minlnsmall being less than -702 is needed to avoid nan being returned close to the limits of double precision floating point accuracy, and it's necessary to multiply minlnsmall by 1.0 rather than 1 otherwise some premature rounding occurs sometimes (but not always).</P>Tue, 12 Aug 2014 09:37:36 GMThttps://community.splunk.com/t5/Splunk-Search/How-to-get-stats-command-to-calculate-with-precision-for-numbers/m-p/178154#M51234dmr1952014-08-12T09:37:36Z