Problem with simulator

BESQUEUT

Senior Member
I think there is a problem with step by step simulation in this erroneous program :
Code:
#picaxe 40X2
#no_table
#simspeed 1

w1=1<<2
w1=1<<15
w1=1<<16
w1=1<<17
w1=1<<31
w1=1<<32
w1=1<<63
w1=1<<127
w1=1<<254
w1=1<<255
PE6 stop working after w1=1<<17

Can you confirm ?
 

Technical

Technical Support
Staff member
You are correct, PE6 is not catching the error which we have now fixed for the next release.
Obviously anything more than <<16 is faulty on 32 bit maths anyway.
 

BESQUEUT

Senior Member
You are correct, PE6 is not catching the error which we have now fixed for the next release.
Obviously anything more than <<16 is faulty on 32 bit maths anyway.
Simulator is supposed to be used for debuging purpose... so this may append...

By the way, are problems with ATAN, SIN and COS fixed ?
 
Last edited:

BESQUEUT

Senior Member

Technical

Technical Support
Staff member
This example works ok for us in simulation. Can you be more precise in where you believe the error is?

Code:
[COLOR=Blue]for [/COLOR][COLOR=Purple]w0 [/COLOR][COLOR=DarkCyan]= 0 [/COLOR][COLOR=Blue]to [/COLOR][COLOR=Navy]360
      [/COLOR][COLOR=Purple]b2 [/COLOR][COLOR=DarkCyan]= sin [/COLOR][COLOR=Purple]w0
      
      [/COLOR][COLOR=Blue]if [/COLOR][COLOR=Purple]b2 [/COLOR][COLOR=DarkCyan]>= [/COLOR][COLOR=Navy]128 [/COLOR][COLOR=Blue]then
            [/COLOR][COLOR=Purple]b2 [/COLOR][COLOR=DarkCyan]= [/COLOR][COLOR=Purple]b2 [/COLOR][COLOR=DarkCyan]- [/COLOR][COLOR=Navy]128
            [/COLOR][COLOR=Blue]sertxd ([/COLOR][COLOR=Black]#[/COLOR][COLOR=Purple]w0[/COLOR][COLOR=Black], [/COLOR][COLOR=Red]" -"[/COLOR][COLOR=Black],#[/COLOR][COLOR=Purple]b2[/COLOR][COLOR=Black],[/COLOR][COLOR=Blue]cr[/COLOR][COLOR=Black],[/COLOR][COLOR=Blue]lf)
      else
            sertxd ([/COLOR][COLOR=Black]#[/COLOR][COLOR=Purple]w0[/COLOR][COLOR=Black], [/COLOR][COLOR=Red]" +"[/COLOR][COLOR=Black],#[/COLOR][COLOR=Purple]b2[/COLOR][COLOR=Black],[/COLOR][COLOR=Blue]cr[/COLOR][COLOR=Black],[/COLOR][COLOR=Blue]lf)
      end if
next [/COLOR][COLOR=Purple]w0[/COLOR]
 

Pongo

Senior Member
Confirm that ATAN simulation is now fixed in 6.0.8. - thanks.

I never saw a problem with SIN.
 

BESQUEUT

Senior Member
This example works ok for us in simulation. Can you be more precise in where you believe the error is?
You are right, and I did not read correctly the documentation :
Note that the 128 is used as a sign indicator and the resulting value is not a two's complement representation.

I understood that it was two's complement... witch is coherent with Picaxes perfectly working with two's complement negatives numbers,
at least for add, substract and multiply.

Maybe a day, we will define a symbol directly as being negative...
symbol toto=-4
 

AllyCat

Senior Member
Hi,

Picaxes perfectly working with two's complement negatives numbers, at least for add, substract and multiply.
PICaxe does not work "perfectly" (or at all) multiplying negative numbers.

For example 255 * 255 (-1 * -1) produces a result of 65025 (-511) not +1 .

Cheers, Alan.
 

BESQUEUT

Senior Member
Hi,

PICaxe does not work "perfectly" (or at all) multiplying negative numbers.

For example 255 * 255 (-1 * -1) produces a result of 65025 (-511) not +1 .

Cheers, Alan.
Ohhhh ! Did not saw that ! Was only trying for -1 *2 or 2*-1
Many thanks : that may be a big problem cause.
I have to verify my code... one operator must be positive for each multiply.

Till usable for add, substract and multiply by a positive integer, that is more than nothing and very usefull for trigo.
(I did rewrote SIN, COS, ASIN, ACOS and ATAN2 to be usable with two-s complement numbers...)
Used to compensate a magnetometer.

I am on the way to write a new library to implement floating point numbers.
 

hippy

Technical Support
Staff member
I understood that it was two's complement... witch is coherent with Picaxes perfectly working with two's complement negatives numbers,
at least for add, substract and multiply.
It is more correct to say that unsigned maths can, in appropriate circumstances, deliver a result as expected when two's complement values are used. In some cases the results will not be as expected. This is particularly so when mixing byte and word variables.
 
Top