nawk: division by zero Problem
am 17.09.2007 16:28:59 von wxkevinI 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?
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?
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.
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.
On Sep 17, 10:54 am, Ed Morton
> 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.
wxkevin@yahoo.com wrote:
> On Sep 17, 10:54 am, Ed Morton
>> 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
wxkevin@yahoo.com wrote:
> On Sep 17, 10:54 am, Ed Morton
>> 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
On Mon, 17 Sep 2007 07:28:59 -0700, wxkevin@yahoo.com
>
>
> 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.
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.
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