#This work is licensed under the
#Creative Commons Attribution-Share Alike 3.0 United States License.
#To view a copy of this license, visit
#http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to
#Creative Commons,
#171 Second Street, Suite 300,
#San Francisco, California, 94105, USA.

INPUT "16 bit signed value";
OUTPUT "signed WavPack exp2 value";
VAR value "value";
if -32768 <= value < -2304 {
    e <- wexp(-value % 256);
    return -(e * 2 ^ {floor(-value / 2 ^ 8) - 9});
} elif -2304 <= value < 0 {
    e <- wexp(-value % 256);
    return -floor(e / 2 ^ {9 - floor(-value / 2 ^ 8)});
} elif 0 <= value <= 2304 {
    e <- wexp(value % 256);
    return floor(e / 2 ^ {9 - floor(value / 2 ^ 8)});
} elif 2304 < value <= 23767 {
    e <- wexp(value % 256);
    return e * 2 ^ {floor(value / 2 ^ 8) - 9};
}
return value;
