mod and using large numbers has strange effects:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
RT
Reply | Threaded
Open this post in threaded view
|

mod and using large numbers has strange effects:

RT
>> realmax
ans = 1.79769313486232e+308

​​
for ii=
​0:360
  z=mod(realmax,ii)
end

​z varies from
z = Inf
z =                    0
z =                    0
z = 1.99584030953472e+292​

​I was expecting z to be between 0​ and 360 what am I doing wrong.


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave
Reply | Threaded
Open this post in threaded view
|

Re: mod and using large numbers has strange effects:

Gordon Haverland
On Thu, 12 Oct 2017 17:58:59 -0400
RT <[hidden email]> wrote:

> >> realmax
> ans = 1.79769313486232e+308
>
> ​​
> for ii=
> ​0:360
>   z=mod(realmax,ii)
> end
>
> ​z varies from
> z = Inf
> z =                    0
> z =                    0
> z = 1.99584030953472e+292​
>
> ​I was expecting z to be between 0​ and 360 what am I doing wrong.

Expecting a reasonable answer.

You have a number, which you may be expecting to be a counting number
(integer) which has 308 decimal places.  If we convert that to base 2,
it will be some huge number of bits.  Octave might be using 8 bytes to
represent a number.  Nowhere near the size you need.

Work with much smaller numbers, and slowly increase them.  Look at how
the error scales with the size of the number.

Gord


_______________________________________________
Help-octave mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-octave