nawk: division by zero Problem

nawk: division by zero Problem

am 17.09.2007 16:28:59 von wxkevin

I have an nawk script that is dividing by a very small number (2.4 X
10^-8). nawk is giving me a divide by zero. Does anybody know of a
workaround?

Re: nawk: division by zero Problem

am 17.09.2007 16:54:41 von Ed Morton

wxkevin@yahoo.com wrote:
> I have an nawk script that is dividing by a very small number (2.4 X
> 10^-8). nawk is giving me a divide by zero. Does anybody know of a
> workaround?
>

Use a different awk, e.g.:

$ gawk 'BEGIN{print 2.4 * (10^-8)}'
2.4e-08

Ed.

Re: nawk: division by zero Problem

am 17.09.2007 17:58:44 von Janis Papanagnou

Ed Morton wrote:
> wxkevin@yahoo.com wrote:
>
>> I have an nawk script that is dividing by a very small number (2.4 X
>> 10^-8). nawk is giving me a divide by zero. Does anybody know of a
>> workaround?
>>
>
> Use a different awk, e.g.:
>
> $ gawk 'BEGIN{print 2.4 * (10^-8)}'
> 2.4e-08

Commonly written just as

$ awk 'BEGIN{print 2.4e-8}'
2.4e-08

And gawk has a much larger scale in divisions of small numbers, as the
OP asked for...

$ awk 'BEGIN{print 1.0/2.4e-300}'
4.16667e+299
$ awk 'BEGIN{print 1.0/2.4e-323}'
inf
$ awk 'BEGIN{print 1.0/2.4e-324}'
awk: fatal: division by zero attempted


Janis ;-)

>
> Ed.

Re: nawk: division by zero Problem

am 17.09.2007 20:29:17 von wxkevin

On Sep 17, 10:54 am, Ed Morton wrote:
> wxke...@yahoo.com wrote:
> > I have an nawk script that is dividing by a very small number (2.4 X
> > 10^-8). nawk is giving me a divide by zero. Does anybody know of a
> > workaround?
>
> Use a different awk, e.g.:
>
> $ gawk 'BEGIN{print 2.4 * (10^-8)}'
> 2.4e-08
>
> Ed.

Unfortunately using another awk is not possible.

Re: nawk: division by zero Problem

am 17.09.2007 22:12:55 von Kenan Kalajdzic

wxkevin@yahoo.com wrote:
> On Sep 17, 10:54 am, Ed Morton wrote:
>> wxke...@yahoo.com wrote:
>> > I have an nawk script that is dividing by a very small number (2.4 X
>> > 10^-8). nawk is giving me a divide by zero. Does anybody know of a
>> > workaround?
>>
>> Use a different awk, e.g.:
>>
>> $ gawk 'BEGIN{print 2.4 * (10^-8)}'
>> 2.4e-08
>>
>> Ed.
>
> Unfortunately using another awk is not possible.

Can you use bc instead?

--
Kenan Kalajdzic

Re: nawk: division by zero Problem

am 17.09.2007 23:54:26 von Michael Tosch

wxkevin@yahoo.com wrote:
> On Sep 17, 10:54 am, Ed Morton wrote:
>> wxke...@yahoo.com wrote:
>>> I have an nawk script that is dividing by a very small number (2.4 X
>>> 10^-8). nawk is giving me a divide by zero. Does anybody know of a
>>> workaround?
>> Use a different awk, e.g.:
>>
>> $ gawk 'BEGIN{print 2.4 * (10^-8)}'
>> 2.4e-08
>>
>> Ed.
>
> Unfortunately using another awk is not possible.
>

Which OS?

Most OS have awk linked with the system math library "libm".
Probably you can install an OS patch for /usr/lib/libm.*

Otherwise you can try this workaround:

nawk 'BEGIN{tiny=1.0e-7; a=2.4e-8; print 1.0 / (a > tiny ? a : tiny)}'

--
Michael Tosch @ hp : com

Re: nawk: division by zero Problem

am 18.09.2007 16:04:57 von Bill Marcum

On Mon, 17 Sep 2007 07:28:59 -0700, wxkevin@yahoo.com
wrote:
>
>
> I have an nawk script that is dividing by a very small number (2.4 X
> 10^-8). nawk is giving me a divide by zero. Does anybody know of a
> workaround?
>
Multiply by the reciprocal, 4.16667e7


--
The grand leap of the whale up the Fall of Niagara is esteemed, by all
who have seen it, as one of the finest spectacles in nature.
-- Benjamin Franklin.

Re: nawk: division by zero Problem

am 18.09.2007 16:33:15 von Ed Morton

Janis Papanagnou wrote:
> Ed Morton wrote:
>
>> wxkevin@yahoo.com wrote:
>>
>>> I have an nawk script that is dividing by a very small number (2.4 X
>>> 10^-8). nawk is giving me a divide by zero. Does anybody know of a
>>> workaround?
>>>
>>
>> Use a different awk, e.g.:
>>
>> $ gawk 'BEGIN{print 2.4 * (10^-8)}'
>> 2.4e-08
>
>
> Commonly written just as
>
> $ awk 'BEGIN{print 2.4e-8}'
> 2.4e-08

I wasn't paying attention. I thought his problem was with 10^-8 being a
small number, and 2.4 was an example of some data he was operating on
but why I didn't notice the lack of a division there when he clearly
stated that, is beyond me. I even read your response a couple of times
and couldn't figure out why you'd bothered to post it before it
eventually dawned on me what I'd done.

Thanks for putting the OP and I on a better track!

Ed.

Re: nawk: division by zero Problem

am 18.09.2007 18:38:30 von Janis Papanagnou

Ed Morton wrote:
>
> I wasn't paying attention. I thought his problem was with 10^-8 being a
> small number, and 2.4 was an example of some data he was operating on
> but why I didn't notice the lack of a division there when he clearly
> stated that, is beyond me. I even read your response a couple of times
> and couldn't figure out why you'd bothered to post it before it
> eventually dawned on me what I'd done.

It may soothe you to hear that, because of your consistently high
quality postings, I've also read your posting a couple of times to
find out where *I* had a misconception, before I posted mine. :-)

Janis