Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

simple problem to divide

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1018
Location: France

france.gif
PostPosted: Wed Feb 29, 2012 12:25 pm    Post subject: simple problem to divide Reply with quote

hello everybody,

on the simulator
this simple program does'nt work
do you have an idea ?

$regfile = "M644def.dat"
$crystal = 11059200

Dim K As Single
Dim Jw As Single

K = 1500475114054
Jw = 97
Jw = K / Jw
Print Jw

many thanks for your help
JP

bascom 2.0.7.3 W7
Back to top
View user's profile Visit poster's website
kimmi

Moderator



Joined: 24 Feb 2006
Posts: 1922
Location: Denmark

denmark.gif
PostPosted: Wed Feb 29, 2012 12:33 pm    Post subject: Reply with quote

Hi JP

K = 1500475114054 do this fit into a single ?

Quote:
Single. Singles are stored as signed 32 bit binary numbers. Ranging in value from 1.5 x 10^45 to 3.4 x 10^38

_________________
/ Kim
Back to top
View user's profile Visit poster's website MSN Messenger
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1018
Location: France

france.gif
PostPosted: Wed Feb 29, 2012 4:02 pm    Post subject: Reply with quote

Thank you Kimmi for your answers

My problem is to divide modulo this big number :
1500475114054 mod 97

I try with excel is work fine, I define the big number as single (yes you right is more than 32bits !)
as double (64 bits) too but with the simulator is does'nt work...


$regfile = "M644def.dat"
$crystal = 11059200 '16000000

Dim K As Double
Dim Jw As Double
Dim J As Double

K = 1500475114054.0
Jw = 97.0
J = K Mod Jw
Print K
Print Jw

Print J ' give 0 on the simulator

J = 1500475114054.0 Mod 97.0

Print J ' give 78 and that is ok

End

JP Crying or Very sad
Back to top
View user's profile Visit poster's website
oe9vfj

Moderator



Joined: 17 Jun 2004
Posts: 269
Location: Austria, Hard

austria.gif
PostPosted: Thu Mar 08, 2012 10:56 pm    Post subject: Reply with quote

Hi,

The MOD function is only useful for number without a fractional part, that are numbers without a part behind the decimal point. So the type for this function are normally INTEGER and LONG.

I checked EXCEL 2007 and and tried your code in the VBA.
It result in any Error with Numeric Overflow.

The help in EXCEL say to the MOD function (translation by google from geman to english):

Quote:
The modulus operator (or remainder) operator divides operand1 by operand2, while floating-point values ​​are rounded to whole numbers and returns only the remainder as a result


I made some tests with different numbers and it always give an error if operand1 is larger than the highest value of datatype LONG.

You can use following code with the "User defined Function" to work with DOUBLE and values higher than the highest value of the datatype LONG:

Code:
Dim K As double
Dim Jw As double
dim e as double

K = 1500475114054
Jw = 97

declare function Double_Modulo(f1 as Double , f2 as Double) as Double

e = double_modulo(k , jw)

print e

end


Function Double_MODULO(F1 AS DOUBLE , F2 AS DOUBLE)
' F1 and F2 should be positive numbers without any fractional part (no digits behind the decimal point)
   local l1 as Double

   l1 = f1 / f2
   l1 = fix(l1)
   l1 = f2 * l1
   Double_modulo = f1 - l1

end function



this code results with 78


best regards Josef

_________________
regards Josef

DOS - File System for BASCOM-AVR on http://members.aon.at/voegel
Back to top
View user's profile Visit poster's website
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 1018
Location: France

france.gif
PostPosted: Fri Mar 09, 2012 11:21 am    Post subject: Reply with quote

Hi joseph and many thanks for your answers

When you said Excel gave an error, it is true with office 2003 but not true with ofice 2010 I chek it again.

here copy of 3 cases Format number without decimal point.

1500475114054 97 78

But anyway, I give you a big "bisou" for your solution !


JP
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum