Division by 0


Closed Thread
Results 1 to 4 of 4

Thread: Division by 0

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108

    Default Division by 0

    What happens when pic divides a number by 0?

    ( I could'n find any thread about that.. )

    Thanks.
    Sylvio,

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    > What happens when PBP divides a number by 0?

    That depends on how you are using them.

    If you have BYTE sized variables, and are returning the result to a byte sized variable, the result is 255.
    Code:
    A  VAR BYTE
    B  VAR BYTE
    C  VAR BYTE
    
    A = 100
    B = 0
    C = A / B
    
    LCDOUT dec C
    
    ; Displays 255
    If the result is being returned to a Word variable, the result will be 65535.
    Code:
    A  VAR BYTE
    B  VAR BYTE
    C  VAR WORD
    
    A = 100
    B = 0
    C = A / B
    
    LCDOUT dec C
    
    ; Displays 65535
    And if the division is done inside another formula or Statement like LCDOUT, the result is assumed to be word sized, and the result will be 65535 ...
    Code:
    A  VAR BYTE
    B  VAR BYTE
    
    A = 100
    B = 0
    
    LCDOUT dec (A / B)
    
    ; displays 65535, even though the variables are Byte sized.
    For word variables, the result will always be 65535

    And finally, if the zero is in a constant expression, the compiler will flag an error
    Code:
    LCDOUT $FE,$C0, dec 100/0
    
    ; Compiler error: Divide by zero while constant folding.
    HTH,
    DT

  3. #3
    Join Date
    Jan 2007
    Location
    Brazil
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    Thanks again Darrel. There could not be a better explanation.

    Another thing.. Man, these instant interrupts stuffs that you show us are pretty handy.. after using it I discover how usefull it is....

    Regards.
    Sylvio,

  4. #4
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sirvo View Post
    Thanks again Darrel. There could not be a better explanation.
    Thanks Sylvio,

    I'm sure Melanie could have at least made it more interesting.

    And, I'm glad you like the Instant Interrupts!
    I might be a little biased, but I don't think I could write a decent program without them anymore.

    Keep the questions coming.
    They're good one's.
    <br>
    DT

Similar Threads

  1. What is wrong with this division?
    By tjkelly in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 5th March 2010, 17:34
  2. Division with some decimal
    By Darklakebridge7 in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 10th May 2007, 06:41
  3. 32 bit Division without DIV32
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 25th October 2006, 08:48
  4. division
    By eoasap in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 28th March 2006, 16:26
  5. Decimals and Digits and Division Oh My!
    By Spindle in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd June 2005, 08:16

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts