bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] Division by zero in floats and complex


From: Juergen Sauermann
Subject: Re: [Bug-apl] Division by zero in floats and complex
Date: Wed, 23 May 2018 13:15:59 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.3.0

Hi Kacper,

thanks, fixed in SVN 1050.

/// Jürgen


On 05/23/2018 04:20 AM, Kacper Gutowski wrote:
Hi,
I'm pretty sure it worked at some point before,
but now (r1049) I encountered the following:

      1.1÷0   ⍝ should signal DOMAIN ERROR like 1÷0 does
0
      1J1÷0   ⍝ ditto
0

And when I tried to ensure division by zero doesn't happen
in the first place, I ran into this:

      a←1.1× b←1 0
      a÷b     ⍝ no error expected here because 0÷0 should be just 1
DOMAIN ERROR
      a÷b
      ^ ^
      2⎕TF 'a'
a←1.1000000000000001 0
      0≡a[2]
1
      a[2]←0  ⍝ numerically the same
      a÷b     ⍝ but now it works
1.1 1

It's different on the first element, though:

      a←1.1× b←0 1
      a÷b     ⍝ wrong result: 0 instead of 1
0 1.1

There's also this:

      0J0÷0   ⍝ should be 1
0

And with larger arrays, I get crashes.  Unfortunately it randomly crashes
in a number of different ways: sometimes a segfault with a stack trace,
sometimes without, and few times I saw it trap illegal instruction. It
seems to jump into some random location.  It doesn't seem to depend on
compiler version because I get similar behavior with both gcc and clang,
but I'm not sure how reproducible it is otherwise:

      a←12⍴0 ⋄ a[1]←1.1 ⋄ a÷0  ⍝ wrong result
0 1 1 1 1 1 1 1 1 1 1 1
      a←12⍴0 ⋄ a[2]←1.1 ⋄ a÷0  ⍝ correct
DOMAIN ERROR
      a÷0
      ^^
      a←13⍴0 ⋄ a[2]←1.1 ⋄ a÷0  ⍝ crashes


====================================================
SEGMENTATION FAULT

----------------------------------------
-- Stack trace at main.cc:88
----------------------------------------
0x7F535AAECA87 __libc_start_main
0x56115F847CE5  main
0x56115F9C541D   Workspace::immediate_execution(bool)
0x56115F89CCBF    Command::process_line()
0x56115F89D5A4     Command::do_APL_expression(UCS_string&)
0x56115F89CD3F      Command::finish_context()
0x56115F8A86E7       Executable::execute_body() const
0x56115F95E0B0        StateIndicator::run()
0x56115F8EB07E         Prefix::reduce_statements()
0x56115F8E5F2B          Prefix::reduce_A_F_B_()
0x56115F95741F           Bif_F12_DIVIDE::eval_AB(Value_P, Value_P)
0x56115F95339F            ScalarFunction::eval_scalar_AB(Value_P, Value_P, ErrorCode (Cell::*)(Cell*, Cell const*) const)
0x56115F952682             ScalarFunction::do_scalar_AB(ErrorCode&, Value_P, Value_P, ErrorCode (Cell::*)(Cell*, Cell const*) const)
0x56115F8AE677              FloatCell::bif_multiply(Cell*, Cell const*) const
0x7F535BE2EF50               
0x56115F84D9DB                
========================================
====================================================

Goodbye.
Session duration: 21.264 seconds 



For completeness, here's what I get from gdb:

      a←13⍴0 ⋄ a[2]←1.1 ⋄ a÷0

Program received signal SIGSEGV, Segmentation fault.
0x000000000000cb12 in ?? ()
(gdb) bt
#0  0x000000000000cb12 in ?? ()
#1  0x000055555564567d in FloatCell::bif_multiply (this=0x555555af1378, 
    Z=0x555555af23b8, A=0x555555af23b8) at FloatCell.cc:494
#2  0x00005555556e9682 in ScalarFunction::do_scalar_AB (
    this=0x5555559fa320 <Bif_F12_DIVIDE::_fun>, 
    address@hidden: E_NO_ERROR, A=..., B=..., fun=<optimized out>)
    at ScalarFunction.cc:500
#3  0x00005555556ea39f in ScalarFunction::eval_scalar_AB (
    this=<optimized out>, A=..., B=..., fun=<optimized out>)
    at ScalarFunction.cc:309
#4  0x00005555556ee41f in Bif_F12_DIVIDE::eval_AB (this=<optimized out>, 
    A=..., B=...) at ScalarFunction.hh:728
#5  0x000055555567cf2b in Prefix::reduce_A_F_B_ (this=0x555555aee600)
    at Prefix.cc:1051
#6  0x000055555568207e in Prefix::reduce_statements (this=0x555555aee600)
    at Prefix.cc:670
#7  0x00005555556f50b0 in StateIndicator::run (this=<optimized out>)
    at StateIndicator.cc:399
#8  0x000055555563f6e7 in Executable::execute_body (this=<optimized out>)
    at Executable.cc:256
#9  0x0000555555633d3f in Command::finish_context () at Command.cc:300
#10 0x00005555556345a4 in Command::do_APL_expression (line=...)
    at Command.cc:288
#11 0x0000555555633bd4 in Command::process_line (line=...) at Command.cc:100
#12 0x0000555555633cbf in Command::process_line () at Command.cc:67
#13 0x000055555575c41d in Workspace::immediate_execution (exit_on_error=false)
    at Workspace.cc:180
#14 0x00005555555dece5 in main (argc=<optimized out>, argv=<optimized out>)
    at main.cc:480
(gdb) up
#1  0x000055555564567d in FloatCell::bif_multiply (this=0x555555af1378, 
    Z=0x555555af23b8, A=0x555555af23b8) at FloatCell.cc:494
494	   if (!A->is_numeric())   return E_DOMAIN_ERROR;
(gdb) p A
$1 = (const Cell *) 0x555555af23b8
(gdb) p *A
$2 = {_vptr.Cell = 0x555555af2440, value = {aval = 512, cval = {
      2.5296161067071823e-321, 6.3240402667679558e-322}, eval = 512, 
    ival = 512, fval = {u1 = {flt = 2.5296161067071823e-321, num = 512}, 
      denominator = 128}, vptr = 0x200, next = 0x200, lval = 0x200, pval = {
      valp = {value_p = 0x200}, owner = 0x80}}}
(gdb) 



And similarly for complex:

      a←13⍴0 ⋄ a[2]←1J0 ⋄ a÷0

Program received signal SIGSEGV, Segmentation fault.
0x0000003500000031 in ?? ()
(gdb) bt
#0  0x0000003500000031 in ?? ()
#1  0x0000555555636cc6 in ComplexCell::bif_multiply (this=<optimized out>, 
    Z=0x555555af23b8, A=<optimized out>) at ComplexCell.cc:293
#2  0x00005555556e9682 in ScalarFunction::do_scalar_AB (
    this=0x5555559fa320 <Bif_F12_DIVIDE::_fun>, 
    address@hidden: E_NO_ERROR, A=..., B=..., fun=<optimized out>)
    at ScalarFunction.cc:500
#3  0x00005555556ea39f in ScalarFunction::eval_scalar_AB (
    this=<optimized out>, A=..., B=..., fun=<optimized out>)
    at ScalarFunction.cc:309
#4  0x00005555556ee41f in Bif_F12_DIVIDE::eval_AB (this=<optimized out>, 
    A=..., B=...) at ScalarFunction.hh:728
#5  0x000055555567cf2b in Prefix::reduce_A_F_B_ (this=0x555555aee600)
    at Prefix.cc:1051
#6  0x000055555568207e in Prefix::reduce_statements (this=0x555555aee600)
    at Prefix.cc:670
#7  0x00005555556f50b0 in StateIndicator::run (this=<optimized out>)
    at StateIndicator.cc:399
#8  0x000055555563f6e7 in Executable::execute_body (this=<optimized out>)
    at Executable.cc:256
#9  0x0000555555633d3f in Command::finish_context () at Command.cc:300
#10 0x00005555556345a4 in Command::do_APL_expression (line=...)
    at Command.cc:288
#11 0x0000555555633bd4 in Command::process_line (line=...) at Command.cc:100
#12 0x0000555555633cbf in Command::process_line () at Command.cc:67
#13 0x000055555575c41d in Workspace::immediate_execution (exit_on_error=false)
    at Workspace.cc:180
#14 0x00005555555dece5 in main (argc=<optimized out>, argv=<optimized out>)
    at main.cc:480
(gdb) up
#1  0x0000555555636cc6 in ComplexCell::bif_multiply (this=<optimized out>, 
    Z=0x555555af23b8, A=<optimized out>) at ComplexCell.cc:293
293	const APL_Complex z = A->get_complex_value() * cval();
(gdb) 


In both cases, executing a method on A goes astray.

-k



Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]