GfMath

GfMath.h

#ifndef __GFMATH_H__
#define __GFMATH_H__

u32 wordAbs(u32,u32);

int intAbs(int, int);

int byteAbs(int , int);

int sameSign(int a,int b,int c);

int getMid(int a,int b,int c);

int inRange(int a,int b,int c);

int getNext(int now,int pre);

#endif



GfMath.c

#include "All_includes.h"

u32 wordAbs(u32 a, u32 b)
{
    if(a > b)
        return (a - b);
    else
        return (b - a);
}

int intAbs(int a, int b)
{
    if(a > b)
        return (int)(a - b);
    else
        return (int)(b - a);
}

int byteAbs(int a, int b){
    if(a > b)
        return (int)(a - b);
    else
        return (int)(b - a);
}

int sameSign(int a,int b,int c){
    if ( a==200 || b==200 || c==200 ) return 0;
    if ( byteAbs(a,b)>5 || byteAbs(b,c)>5 || byteAbs(a,c)>5 ) return 0;
    if ( a<=b && b<=c || a>=b && b>=c ) return 1;
    return 0;
}

int getMid(int a,int b,int c)
{   
  if(a > b){a ^= b ^= a ^= b}
  if(b > c){b ^= c ^= b ^= c}
  if(a > b){a ^= b ^= a ^= b}
  return b;
}

int inRange(int pre,int now,int next)
{
    if (now == pre && pre == 0)
    {              //允许跳一半
        if (next < 80) return 1;
        else return 0;
    }
    if (now == pre && pre == 160)
    {
        if (next > 80) return 1;
        else return 0;
    }
    if (pre > now)
    {
        if (next <= now)
        {
            if (MAX((now << 1) - pre - 5, 0) <= next) return 1;
        }
        else 
        {
            if (pre - now + next - now < 5) return 1;
        }
    }
    else 
    {           
        if (next >= now){
            if (next <= MIN((now << 1) - pre + 5, 160)) return 1;
        }
        else 
        {
            if (now - pre + now - next < 5) return 1;
        }
    }            
    return 0;
}

int getNext(int now,int pre)
{
    int next;
    if ( now > pre )
    {          
        next = MIN((int)((now << 1) - pre), 160);            
    }
    else if ((now << 1) > pre)
    {
        next = (now << 1) - pre;
    }
    else next = 0;
    return next;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值