● fixed X - 関数リファレンス

FIXEDVAL値の交換

    void __stdcall   fixed_exchange(PFIXEDVAL px ,PFIXEDVAL py ,int width );

引数

引数名意味
px値が格納されている FIXEDVAL領域の先頭アドレス
py値が格納されている FIXEDVAL領域の先頭アドレス
widthpxpy の指す FIXEDVAL値の数値幅(バイト単位)

戻り値

無し

説明

pxpy の指す FIXEDVAL領域の内容を交換します。


引数 pxpy の指す領域は、両方共 width が示す数値幅以上のサイズを持っている必要があり、width は 4 の倍数である必要があります。


テスト.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "fixedX.h"

#define BIT             128
#define SIZE            (BIT / 8)
#define NUMSIZE         39
#define CNT             10

typedef FIXEDVAL    FVAL[SIZE];

FVAL            val_array[CNT];

void    main(void)
{
    FIXEDVAL    temp2[SIZE * 2];
    char        buf[NUMSIZE+1];
    int         i;
    FVAL        *pp1,*pp2,*pp3;

    srand((unsigned int)time(NULL));

    for(i = 0;i < CNT;i++){

        /* ランダム値を 1,000,000,000倍し、val_array に格納 */
        *(unsigned long *)val_array[i] = rand();
        fixed_mul32(val_array[i],1000000000UL,temp2,SIZE);
        memcpy(val_array[i],temp2,SIZE);

        /*
          セットした値を表示
          指定した変数の内容は破壊されるので、乗算で使用した temp2 に
          残っている数値を使用する
        */
        fixed_num2str10(temp2,SIZE,buf);
        printf("%s\n",buf);
    }
    printf("\n");

    /* バブルソートで降順に並び替える */
    for(pp1 = val_array + CNT - 1;pp1 >= val_array;pp1 = pp3)
        for(pp3 = NULL,pp2 = val_array + 1;pp2 <= pp1;pp2++)
            if (fixed_cmp(pp2[-1],*pp2,SIZE) < 0)
                fixed_exchange(*pp2,*(pp3 = pp2 - 1),SIZE);

    /*
      並び替えた結果を表示する
      これ以降、配列の内容は不要なので、配列を直接fixed_num2str10 に
      指定する
    */
    for(i = 0;i < CNT;i++){
        fixed_num2str10(val_array[i],SIZE,buf);
        printf("%s\n",buf);
    }
}