Potential bug

1 view
Skip to first unread message

Dragon

unread,
Jun 3, 2008, 1:09:09 AM6/3/08
to freemat-devel
I did a quick and simple test to see if the computational power of the
program can hold up with Matlab. My test was to work out the factorial
with increasing order. This was done with a for loop though this
should hardly matter. The factorial of 12 is still correct but the
factorial of 13 is way off. I have tried to see if changing the
variable to a double type would make a difference but it did not. Also
if it is a variable type problem the program offers no warnings or
error messages.

Can someone tell me if I am missing something here or is this a bug?

Timothy Cyders

unread,
Jun 3, 2008, 8:23:41 AM6/3/08
to freema...@googlegroups.com
Dragon, could you post your loop and output? Thanks!

TJ

Timothy Cyders

unread,
Jun 3, 2008, 8:45:14 AM6/3/08
to freema...@googlegroups.com
I just played with this myself and found similar results:

(x is 12 factorial)

--> 13*x                                                                                                                                                           
ans =                                                                                                                                                                1932053504                                                                                                                                                        

--> ans/13                                                                                                                                                         
ans =                                                                                                                                                                1.4862e+008                                                                                                                                                       

--> x                                                                                                                                                              
ans =                                                                                                                                                                479001600                                                                                                                                                        
 -->  

More interestingly, further iterations go negative:


--> 14*x
ans =
 -1883912192


--> 15*x

ans =
 -1404910592

--> 16*x

ans =
 -925908992

If you divide this final number by 16, you get the correct answer - same with any of them. Seems like it might be bad array storage or something with the multiplication function? I went ahead and started to run a test, looks like multiplication in general is falling apart after 11 digits are needed for storage. I started by doing this:

--> x = 1000000000:1000000:2000000000;
-->for i = 1:length(x)
n = x(i)*2;
if n/2 == x(i)
u(i) = 1;
else u(i) = 2;
end
end

u goes to 2 at i = 75, I don't have time to finish this now, but you can continue to go with smaller steps for x (go from x = 1074000000 to x = 1075000000 and narrow down from there), and we should be able to pinpoint the exact number at which the problem occurs (I'd guess it's some power of two in there). Hope this helps, I have to run to class.

TJ

Timothy Cyders

unread,
Jun 3, 2008, 11:45:00 AM6/3/08
to freema...@googlegroups.com
Pinpointed the problem, it's when the product (or any value in the multiplication) is larger than 2^32. Don't have time to figure out why, but there's the issue.

TJ

Dragon

unread,
Jun 3, 2008, 4:34:18 PM6/3/08
to freemat-devel
Thanx for the time and effort. I did this check early this morning
before work and haven't had time to look at it further.
This could however be a potentially dangerous result should you run
iterative loops or calculations.

Will let you know as soon as I find out any more.

Dragon
> > On Tue, Jun 3, 2008 at 8:23 AM, Timothy Cyders <t.cyd...@gmail.com> wrote:
>
> >> Dragon, could you post your loop and output? Thanks!
>
> >> TJ
>
> >> On Tue, Jun 3, 2008 at 1:09 AM, Dragon <TmanFran...@gmail.com> wrote:
>
> >>> I did a quick and simple test to see if the computational power of the
> >>> program can hold up with Matlab. My test was to work out the factorial
> >>> with increasing order. This was done with a for loop though this
> >>> should hardly matter. The factorial of 12 is still correct but the
> >>> factorial of 13 is way off. I have tried to see if changing the
> >>> variable to a double type would make a difference but it did not. Also
> >>> if it is a variable type problem the program offers no warnings or
> >>> error messages.
>
> >>> Can someone tell me if I am missing something here or is this a bug?- Hide quoted text -
>
> - Show quoted text -

Dragon

unread,
Jun 4, 2008, 11:55:30 AM6/4/08
to freemat-devel
I found that the value in the workspace area is actually correct for
these problems although what it writes in the output screen is wrong.
There must be some kind of problem with the writing procedure or
somewhere along the line the double format is converted to a 32bit
format before writing to the screen.

Dragon
> > - Show quoted text -- Hide quoted text -

EI

unread,
Jun 4, 2008, 7:29:30 PM6/4/08
to freema...@googlegroups.com
Dragon,

Could you please file a bug report about this: http://sourceforge.net/projects/freemat

We'll try to fix this issue for the next release.

Thank you,
Eugene
Reply all
Reply to author
Forward
0 new messages