Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Some ARM processors have hardware floating-point, and some don't, so it's possible that this function is being compiled for hardware floating-point but your platform lacks a floating-point unit, so the floating-point instructions cause the processor to report an illegal instruction. If this is the first floating-point computation in your test program, that's extremely likely to be the problem. Check your platform's documentation to find which -march option you need to pass to gcc, or look at the compilation options used by some program that already works.</p> <p>This function does not have defined behaviour, and without an indication of what the desired behaviour is it's hard to suggest an improvement. Try something like this for a start:-</p> <pre><code>void convertFloatToFixed(float nX, float nY, unsigned int &amp;nFixed) { assert(nX * 32 &lt; INT_MAX); assert(nY * 32 &lt; INT_MAX); int sx = nX * 32; int sy = nY * 32; unsigned int ux = sx; unsigned int uy = sy; nFixed = (ux &lt;&lt; 16) | uy; } </code></pre> <p>I've got rid of the pointer casts, which (as others have pointed out) break the strict aliasing rule. I've also used <code>int</code> instead of <code>short</code>. There's generally no point having <code>short</code> auto variables, since they're widened to <code>int</code>s before computations anyway. (It's a good job they are, as shifting a <code>short</code> by 16 bits would not be very useful.) I've added some checks so your debug builds can find out if the float-to-integer conversion will overflow, which causes undefined behaviour.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload