cocos2d/cocos/audio/android/audio_utils/include/audio_utils/primitives.h
static inline int32_t clamp32_from_float(float f)
{
    static const float scale = (float)(1UL << 31);
    static const float limpos = 1.;
    static const float limneg = -1.;

    if (f <= limneg) {
        return -0x80000000; /* or 0x80000000 */
    } else if (f >= limpos) {
        return 0x7fffffff;
    }
    f *= scale;
    /* integer conversion is through truncation (though int to float is not).
     * ensure that we round to nearest, ties away from 0.
     */
    return f > 0 ? f + 0.5 : f - 0.5;
}
/* Convert a single-precision floating point value to a Q0.31 integer value.
 * Rounds to nearest, ties away from 0.
 *
 * Values outside the range [-1.0, 1.0) are properly clamped to -2147483648 and 2147483647,
 * including -Inf and +Inf. NaN values are considered undefined, and behavior may change
 * depending on hardware and future implementation of this function.
 */
Convert a single-precision floating point value to a Q0.31 integer value.
Rounds to nearest, ties away from 0.


Convert a single - precision floating point value to a Q0 . 31 integer value . Rounds to nearest ties away from 0 .
static inline int32_t clamp32_from_float(float f)
{
    static const float scale = (float)(1UL << 31);
    static const float limpos = 1.;
    static const float limneg = -1.;
    if (f <= limneg) {
        return -0x80000000; 
    } else if (f >= limpos) {
        return 0x7fffffff;
    }
    f *= scale;
    return f > 0 ? f + 0.5 : f - 0.5;
}
static inline int32_t clamp32_from_float ( float f ) { static const float scale = ( float ) ( 1UL << 31 ) ; static const float limpos = 1. ; static const float limneg = -1. ; if ( f <= limneg ) { return -0x80000000 ; } else if ( f >= limpos ) { return 0x7fffffff ; } f *= scale ; return f > 0 ? f + 0.5 : f - 0.5 ; }
Convert a single-precision floating point value to a Q0.31 integer value.
Convert a single - precision floating point value to a Q0 . 31 integer value .
/* or 0x80000000 */ /* integer conversion is through truncation (though int to float is not).
     * ensure that we round to nearest, ties away from 0.
     */