View previous topic :: View next topic |
Author |
Message |
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Wed Feb 29, 2012 12:25 pm Post subject: simple problem to divide |
|
|
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 |
|
|
kimmi
Joined: 24 Feb 2006 Posts: 1922 Location: Denmark
|
Posted: Wed Feb 29, 2012 12:33 pm Post subject: |
|
|
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 |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Wed Feb 29, 2012 4:02 pm Post subject: |
|
|
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 |
|
Back to top |
|
|
oe9vfj
Joined: 17 Jun 2004 Posts: 269 Location: Austria, Hard
|
Posted: Thu Mar 08, 2012 10:56 pm Post subject: |
|
|
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 |
|
|
Duval JP
Joined: 22 Jun 2004 Posts: 1161 Location: France
|
Posted: Fri Mar 09, 2012 11:21 am Post subject: |
|
|
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 |
|
|
|