The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Rmod not working as it should?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

andrewdsto

Australia
Posts

Posted - 07/16/2015 :  03:15:28 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. 2015 and Service Release sr2 (Select Help-->About Origin):
Operating System:Windows 7

Hi,
Just a short question on the rmod function. I dont think it is working as it should, see below.

rmod(6,2)=;
returns
rmod(6,2)=0

All ok, same the mod function. now

5*4.2=;
rmod(21,4.2)=;

we get

5*4.2=21
rmod(21,4.2)=4.2

however

rmod(21,5)=;
returns
rmod(21,5)=1

again ok
and

rmod(21,4.1)=;
returns
rmod(21,4.1)=0.5

again ok

its only when the remainder is meant to be zero we instead get the divisor.

interestingly if we run the folowing
4.2*6=;
25.2-(6*4.2)=;

we get
4.2*6=25.2
25.2-(6*4.2)=-3.5527136788005E-15

that is we do not get zero but instead a very small number.

I am thinking that where the modulus is zero, the rmod funtion infact returns not zero but a number that is very close to, but just below, the divisor which gets returned as the divisor. But this is only for real numbers and not integers.

just a thought.

thanks
Andrew

SeanMao

China
288 Posts

Posted - 07/16/2015 :  04:41:31 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

This is due to the rounding error, when you do rmod(21,4.2) you actually get remainder 4.199999... rather precise 0.

Regards!

Sean

OriginLab Tech. Service

Edited by - SeanMao on 07/16/2015 04:42:12 AM
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000