Jump to content

Division By Zero - What Happens In This Case?

Recommended Posts

Most PIC processors do not have hardware divide logic so division is done in software. It is up to the compiler to decide to implement exception handling or not. Since code space is usually a premium, I would expect that BoostC does nothing but give you a bad answer. For most tiny embedded processors, you will have to check your inputs and handle divide by zero yourself so that you can handle it the way that is best for your application.

Link to post
Share on other sites

If the PC jumped to a certain location it would tell you in the manual.


It is your responsibility to check the value of the divisor if there is a possibility of it being zero.


As trossin said division is performed in software. If a divide by zero happens then the result would probably be the maximum value for the data type.


If you are using the floating point library then the float_exception_flags would inform you that a divide by zero occurred.

It is your responsibility to check these flags. See manual.


If you write a small program and run the simulator you can test for yourself what happens.


I hope this sheds some light for you.





Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...