[Bug 275661] /usr/bin/dc hangs with a trivial calculation

From: <bugzilla-noreply_at_freebsd.org>
Date: Sun, 10 Dec 2023 05:37:07 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=275661

--- Comment #2 from Dennis Clarke <dclarke@blastwave.org> ---
(In reply to Mark Millard from comment #1)

Excellent !  Thank you. I knew it was from Scientific American but clearly
not Martin Gardner.

Also, it seems that dc is not hung or strangely locked up. It is just
very very very slow. Also it gets slower and slower depending on the
exponent in this trivial computation : 

(1) firstly I need something that will kick out the current UNIX time
    along with the subseconds :

https://git.sr.ht/~blastwave/bw/tree/bw/item/time_and_date/timenow/tn.c

pluto$ cc -std=iso9899:1999 -g -O0 -m64 -o $HOME/bin/tn
/opt/bulk/users/dclarke/tn.c
pluto$ $HOME/bin/tn
1702150944
pluto$ bin/tn -f
1702150948.185400780

I can generally trust that time data down to the millisecond but no further.

(2) try that same computation with an exponent of 2^21 :

pluto$ bin/tn -f ; echo "16k 1.0000001 2 21^ ^ pq" | dc ; bin/tn -f
1702150982.359058318
1.2333267455406059
1702151041.388274513
pluto$ echo '16k 1702151041.388274513 1702150982.359058318 - pq' | dc
59.029216195

(3) same thing again with 2^22 :

pluto$ bin/tn -f ; echo "16k 1.0000001 2 22^ ^ pq" | dc ; bin/tn -f
1702151116.511391274
1.5210948612657825
1702151292.913553255
pluto$ echo '16k 1702151292.913553255 1702151116.511391274 - pq' | dc
176.402161981

(4) and now 2^23

pluto$ bin/tn -f ; echo "16k 1.0000001 2 23^ ^ pq" | dc ; bin/tn -f
1702151370.327805625
2.3137295769691702
1702151899.256797300
pluto$ echo '16k 1702151899.256797300 1702151370.327805625 - pq' | dc
528.928991675

(5) things are really getting slow with 2^24

pluto$ bin/tn -f ; echo "16k 1.0000001 2 24^ ^ pq" | dc ; bin/tn -f
1702152105.644851540
5.3533445553419354
1702153691.392552070
pluto$ echo '16k 1702153691.392552070 1702152105.644851540 - pq' | dc
1585.747700530

(6) again with 2^25

pluto$ bin/tn -f ; echo "16k 1.0000001 2 25^ ^ pq" | dc ; bin/tn -f
1702154005.973187537
28.6582979282091444
1702158766.756840716
pluto$  
pluto$ echo '16k 1702158766.756840716 1702154005.973187537 - pq' | dc
4760.783653179

It looks like a factor of three increase in time required with each
test.

The test for 2^26 is still running and I expect 5 hours or so will be
needed and that means the computation with 2^27 may be about 16 hours
or so.

Dennis

-- 
You are receiving this mail because:
You are the assignee for the bug.