Hello all,

I did a test (on my fantastic JALPIC One board) and tried the following.  Form 
this test the following results were obtained:

  1.
0x0010 = 16
  2.
0x03e8 = 1000
  3.
0x03e8 = 1000
  4.
0x0010 = 16
  5.
0x0010 = 16
  6.
0x03e8 = 1000 (I added this one)

So casting works when applied correctly

----- Code -----

var word a = 5000
var word b = 200​
var dword c​


   print_string(serial_hw_data,"1\r\n")
   c = a*b/1000​
   print_dword_hex(serial_hw_data,c)​
   print_crlf(serial_hw_data)​
   _usec_delay(1_000_000)​
​
   print_string(serial_hw_data,"2\r\n")​
   c = dword(a)*b/1000​
   print_dword_hex(serial_hw_data,c)​
   print_crlf(serial_hw_data)​
   _usec_delay(1_000_000)​
   ​
   print_string(serial_hw_data,"3\r\n")​
   c = a*dword(b)/1000​
   print_dword_hex(serial_hw_data,c)​
   print_crlf(serial_hw_data)​
   _usec_delay(1_000_000)​
   ​
   print_string(serial_hw_data,"4\r\n")​
   c = dword(a*b)/1000​
   print_dword_hex(serial_hw_data,c)​
   print_crlf(serial_hw_data)​
   _usec_delay(1_000_000)​
   ​
   print_string(serial_hw_data,"5\r\n")​
   c = dword(a*b)/1000​
   print_dword_hex(serial_hw_data,c)​
   print_crlf(serial_hw_data)​
   _usec_delay(1_000_000)​
​
   print_string(serial_hw_data,"6\r\n")​
   c = (dword(a)* dword(b))/1000​
   print_dword_hex(serial_hw_data,c)​
   print_crlf(serial_hw_data)​
   _usec_delay(1_000_000)​

Kind regards,

Rob


________________________________
Van: [email protected] <[email protected]> namens Matthew Schinkel 
<[email protected]>
Verzonden: zondag 31 maart 2019 23:50
Aan: jallib
Onderwerp: [jallib] Re: 5000*200/1000=16?

There may be something wrong with the rest of your code, please post it.

Go through your code slowly to find the issue:

With this line, you can manually find the reason C = 16
var dword c= (a*b)/1000

200*5000 = hex 0xF4240, or as a word it is truncated to 0x4240
0x4240 = 16960
16960 / 1000 = 16

The compiler did what it is supposed to do.

what result do you get with (dword(a)*b)/1000? Is your casting correct in the 
rest of the program?

Matt.


On Sunday, March 31, 2019 at 5:27:06 PM UTC-4, Rian De Rous wrote:
Casting one or both variables when performing the multiply operation does not 
fix this.

Tried

var word a = 5000
var word b = 200
var dword c


-- tried this, but none of these produce the right output on the display
c = a*b/1000
c = dword(a)*b/1000
c = a*dword(b)/1000
c = dword(a*b)/1000


--
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
[email protected]<mailto:[email protected]>.
To post to this group, send email to 
[email protected]<mailto:[email protected]>.
Visit this group at https://groups.google.com/group/jallib.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/jallib.
For more options, visit https://groups.google.com/d/optout.

Reply via email to