Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
fixed.cpp
00001 /* 00002 * libmad - MPEG audio decoder library 00003 * Copyright (C) 2000-2004 Underbit Technologies, Inc. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 * 00019 * $Id: fixed.c,v 1.1 2010/11/23 20:12:57 andy Exp $ 00020 */ 00021 00022 # include "config.h" 00023 00024 # include "global.h" 00025 00026 # include "fixed.h" 00027 00028 /* 00029 * NAME: fixed->abs() 00030 * DESCRIPTION: return absolute value of a fixed-point number 00031 */ 00032 mad_fixed_t mad_f_abs(mad_fixed_t x) 00033 { 00034 return x < 0 ? -x : x; 00035 } 00036 00037 /* 00038 * NAME: fixed->div() 00039 * DESCRIPTION: perform division using fixed-point math 00040 */ 00041 mad_fixed_t mad_f_div(mad_fixed_t x, mad_fixed_t y) 00042 { 00043 mad_fixed_t q, r; 00044 unsigned int bits; 00045 00046 q = mad_f_abs(x / y); 00047 00048 if (x < 0) { 00049 x = -x; 00050 y = -y; 00051 } 00052 00053 r = x % y; 00054 00055 if (y < 0) { 00056 x = -x; 00057 y = -y; 00058 } 00059 00060 if (q > mad_f_intpart(MAD_F_MAX) && 00061 !(q == -mad_f_intpart(MAD_F_MIN) && r == 0 && (x < 0) != (y < 0))) 00062 return 0; 00063 00064 for (bits = MAD_F_FRACBITS; bits && r; --bits) { 00065 q <<= 1, r <<= 1; 00066 if (r >= y) 00067 r -= y, ++q; 00068 } 00069 00070 /* round */ 00071 if (2 * r >= y) 00072 ++q; 00073 00074 /* fix sign */ 00075 if ((x < 0) != (y < 0)) 00076 q = -q; 00077 00078 return q << bits; 00079 }
Generated on Tue Jul 12 2022 23:11:09 by
1.7.2