help-octave
[Top][All Lists]
Advanced

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

Re: Calculation issue with octave (data unexpectedly go to zero at some


From: Brian Kaczynski
Subject: Re: Calculation issue with octave (data unexpectedly go to zero at some point)
Date: Fri, 28 Feb 2014 01:13:16 +0100

2014-02-28 1:03 GMT+01:00 Dmitri A. Sergatskov <address@hidden>:
It could be  that there is a bug in mod:

octave:20> mod(0.2, 0.2)
ans = 0
octave:21> mod(0.4, 0.2)
ans = 0
octave:22> mod(0.6, 0.2)
ans =  0.20000                                  # ??????????????

octave:23> mod(0.8, 0.2)
ans = 0


In general it seems like a really bad idea to call mod with non-integer arguments.

Question to the OP:  Is there a way to convert these non-integer arguments to integers by applying something like the following:

a = 0.6; b = 0.2; % non-integer arguments for mod()
a_int = round(2^32*a);
b_int = round(2^32*b);
m = mod(a_int,b_int)/2^32;

This method may give you very small errors on the order of 2^-32 due to round-off error, but this may be better than the problems you're currently facing.


 

Dmitri.

_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave



reply via email to

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