### Author Topic: A good way to deal with negative values  (Read 7264 times)

0 Members and 1 Guest are viewing this topic.

#### SourceCoder2

• LV1 Newcomer (Next: 20)
• Posts: 13
• Rating: +0/-0
##### Re: A good way to deal with negative values
« Reply #15 on: June 20, 2010, 11:45:57 pm »
HH
KermMartian has just edited this program.  The source code now reads:
Quote from: BASIC Code
:.SSS
:‾5→A
:If A>5
:4→A
:End
:If A<<‾5
:‾4→A
:End
:A→Ans
Generated by SourceCoder, © 2005-2010 Cemetech
This is an automatic post from SourceCoder 2.  Report abuse to [email protected] . You can disable these posts by unchecking the "Post on Update" box in the file's permissions.

#### Quigibo

• The Executioner
• CoT Emeritus
• LV11 Super Veteran (Next: 3000)
• Posts: 2031
• Rating: +1075/-24
• I wish real life had a "Save" and "Load" button...
##### Re: A good way to deal with negative values
« Reply #16 on: June 21, 2010, 01:01:06 am »
-5>5 is true since this is unsigned so A should be 4 now
4<<-5 is false since this is signed (like basic) so A is still 4

Is it outputting something else?

Unless my understanding of how signed comparisons work, the routine should always work.
Code: [Select]
xor a          ;Make A zerold b,h         ;H is saved for latersbc hl,de      ;The values are compared unsigned (carry flag)ld h,a         ;Command returns 1 or 0 so high byte is zeroedrra            ;Carry is put into bit 7 of axor b          ;Bit 7 is xored with sign bit of original left argumentxor d          ;Bit 7 is xored with sign bit of original right argumentrlca           ;Bit 7 put into bit 0and %00000001  ;Mask to make this a 1 or 0ld l,a         ;HL holds (sign1 xor sign2 xor comparison)
___Axe_Parser___
Today the calculator, tomorrow the world!

#### DJ Omnimaga

• Clacualters are teh gr33t
• CoT Emeritus
• LV15 Omnimagician (Next: --)
• Posts: 55942
• Rating: +3154/-232
• CodeWalrus founder & retired Omnimaga founder
##### Re: A good way to deal with negative values
« Reply #17 on: June 21, 2010, 01:09:23 am »
It outputs 1 for the first and 0 for the second

#### Quigibo

• The Executioner
• CoT Emeritus
• LV11 Super Veteran (Next: 3000)
• Posts: 2031
• Rating: +1075/-24
• I wish real life had a "Save" and "Load" button...
##### Re: A good way to deal with negative values
« Reply #18 on: June 21, 2010, 01:27:46 am »
Which is exactly what it should... am I missing something?
___Axe_Parser___
Today the calculator, tomorrow the world!

#### DJ Omnimaga

• Clacualters are teh gr33t
• CoT Emeritus
• LV15 Omnimagician (Next: --)
• Posts: 55942
• Rating: +3154/-232
• CodeWalrus founder & retired Omnimaga founder
##### Re: A good way to deal with negative values
« Reply #19 on: June 21, 2010, 01:29:46 am »
Yeah. So this means there is something wrong in my code, but I am not too sure what checks to do