This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Integer division rounding in TMS470 and C6000

What are the results of the following signed integer divisions (on arm TMS470 and dsp C6000 compilers):

1- positive / positive? (truncate. ex. 10/3 = 3)

2- positive / negative? (....?)

3- negative / negative? (truncate. ex. -10/-3=3)

I searched on the compiler datasheets but didn't find an answer.

  • Hi,

    The C6000 compiler is compliant to the standards as stated in §6.1 and 6.2 of the compiler manual, so it always truncates (this is not an implementation-defined behavior).

    The division is implemented in the run-time support (such as __c6xabi_divi) and the C6000 EABI also state it "operate according to C semantics" (see sprab89 §7.2).

  • The TI compilers conform to the C89 standard, which says that if either operand is negative, the result is implementation defined.  The C99 standard changes this to "the result of the / operator is the algebraic quotient with any fractional part discarded."  In the footnote, it says "This is often called 'truncation toward zero.'" 

    All TI compilers truncate integer division toward zero.