📄 flint.c
字号:
sizeof (lb), &lb)); ISPURGED_L ((2, sizeof (la), &la, sizeof (lb), &lb)); return 1; } if (la < lb) { PURGEVARS_L ((2, sizeof (la), &la, sizeof (lb), &lb)); ISPURGED_L ((2, sizeof (la), &la, sizeof (lb), &lb)); return -1; } msdptra_l = a_l + la; msdptrb_l = b_l + lb; while ((*msdptra_l == *msdptrb_l) && (msdptra_l > a_l)) { msdptra_l--; msdptrb_l--; } PURGEVARS_L ((2, sizeof (la), &la, sizeof (lb), &lb)); ISPURGED_L ((2, sizeof (la), &la, sizeof (lb), &lb)); if (msdptra_l == a_l) { return 0; } if (*msdptra_l > *msdptrb_l) { return 1; } else { return -1; }}/******************************************************************************//* *//* Function: Generation of maximum CLINT value 2^CLINTMAXBIT - 1 *//* Syntax: clint * setmax_l (CLINT a_l); *//* Input: a_l CLINT variable *//* Output: a_l set to value of 2^CLINTMAXBIT - 1 = Nmax *//* Returns: Address of CLINT variable a_l *//* *//******************************************************************************/clint * __FLINT_APIsetmax_l (CLINT a_l){ clint *aptr_l = a_l; clint *msdptra_l = a_l + CLINTMAXDIGIT; while (++aptr_l <= msdptra_l) { *aptr_l = BASEMINONE; } SETDIGITS_L (a_l, CLINTMAXDIGIT); return (clint *)a_l;}/******************************************************************************//* *//* Function: Addition of two CLINT operands *//* Syntax: int add_l (CLINT a_l, CLINT b_l, CLINT s_l); *//* Input: a_l, b_l (Operands) *//* Output: s_l (Sum) *//* Returns: E_CLINT_OK : Everything O.K. *//* E_CLINT_OFL: Overflow *//* *//******************************************************************************/int __FLINT_APIadd_l (CLINT a_l, CLINT b_l, CLINT s_l){ clint ss_l[CLINTMAXSHORT + 1]; int OFL = 0; add (a_l, b_l, ss_l); if (DIGITS_L (ss_l) > (USHORT)CLINTMAXDIGIT) /* Overflow ? */ { ANDMAX_L (ss_l); /* Reduction modulo Nmax+1 */ OFL = E_CLINT_OFL; } cpy_l (s_l, ss_l); /* Purging of variables */ PURGEVARS_L ((1, sizeof (s_l), ss_l)); ISPURGED_L ((1, sizeof (s_l), ss_l)); return OFL;}/******************************************************************************//* *//* Function: Subtraction of one CLINT operand from another *//* Syntax: int sub_l (CLINT aa_l, CLINT bb_l, CLINT d_l); *//* Input: aa_l, bb_l (Operands) *//* Output: d_l (Value of a_l - b_l) *//* Returns: E_CLINT_OK : Everything O.K. *//* E_CLINT_UFL: Underflow *//* *//******************************************************************************/int __FLINT_APIsub_l (CLINT aa_l, CLINT bb_l, CLINT d_l){ CLINT b_l; clint a_l[CLINTMAXSHORT + 1], t_l[CLINTMAXSHORT + 1], tmp_l[CLINTMAXSHORT + 1]; int UFL = 0; cpy_l (b_l, bb_l); if (LT_L (aa_l, b_l)) /* Underflow ? */ { setmax_l (a_l); /* We calculate with Nmax */ cpy_l (t_l, aa_l); /* aa_l will be needed once again, ...*/ UFL = E_CLINT_UFL; /* ... will be corrected at the end */ } else { cpy_l (a_l, aa_l); } sub (a_l, b_l, tmp_l); if (UFL) { /* Underflow ? */ add_l (tmp_l, t_l, d_l); /* Correction needed */ inc_l (d_l); /* One is missing */ } else { cpy_l (d_l, tmp_l); } /* Purging of variables */ PURGEVARS_L ((4, sizeof (a_l), a_l, sizeof (b_l), b_l, sizeof (t_l), t_l, sizeof (tmp_l), tmp_l)); ISPURGED_L ((4, sizeof (a_l), a_l, sizeof (b_l), b_l, sizeof (t_l), t_l, sizeof (tmp_l), tmp_l)); return UFL;}/******************************************************************************//* *//* Function: Increment *//* Syntax: int inc_l (CLINT a_l); *//* Input: a_l (CLINT value) *//* Output: a_l, incremented by 1 *//* Returns: E_CLINT_OK : Everything O.K. *//* E_CLINT_OFL: Overflow *//* *//******************************************************************************/int __FLINT_APIinc_l (CLINT a_l){ clint *msdptra_l, *aptr_l = LSDPTR_L (a_l); ULONG carry = BASE; int OFL = 0; msdptra_l = MSDPTR_L (a_l); while ((aptr_l <= msdptra_l) && (carry & BASE)) { *aptr_l = (USHORT)(carry = 1UL + (ULONG)(*aptr_l)); aptr_l++; } if ((aptr_l > msdptra_l) && (carry & BASE)) { *aptr_l = 1; INCDIGITS_L (a_l); if (DIGITS_L (a_l) > (USHORT)CLINTMAXDIGIT) /* Overflow ? */ { SETZERO_L (a_l); /* Reduction modulo Nmax+1 */ OFL = E_CLINT_OFL; } } /* Purging of variables */ PURGEVARS_L ((1, sizeof (carry), &carry)); ISPURGED_L ((1, sizeof (carry), &carry)); return OFL;}/******************************************************************************//* *//* Function: Decrement *//* Syntax: int dec_l (CLINT a_l); *//* Input: a_l (CLINT value) *//* Output: a_l, decremented by 1 *//* Returns: E_CLINT_OK : Everything O.K. *//* E_CLINT_UFL: Underflow *//* *//******************************************************************************/int __FLINT_APIdec_l (CLINT a_l){ clint *msdptra_l, *aptr_l = LSDPTR_L (a_l); ULONG carry = DBASEMINONE; if (DIGITS_L (a_l) == 0) /* Underflow ? */ { setmax_l (a_l); /* Reduction modulo Nmax+1 */ return E_CLINT_UFL; } msdptra_l = MSDPTR_L (a_l); while ((aptr_l <= msdptra_l) && (carry & (BASEMINONEL << BITPERDGT))) { *aptr_l = (USHORT)(carry = (ULONG)*aptr_l - 1L); aptr_l++; } /* Purging of variables */ PURGEVARS_L ((1, sizeof (carry), &carry)); ISPURGED_L ((1, sizeof (carry), &carry)); RMLDZRS_L (a_l); return E_CLINT_OK;}/******************************************************************************//* *//* Function: Multiplication *//* Syntax: int mul_l (CLINT f1_l, CLINT f2_l, CLINT pp_l); *//* Input: f1_l, f2_l (Factors) *//* Output: p_l (Product) *//* Returns: E_CLINT_OK : Everything O.K. *//* E_CLINT_OFL: Overflow *//* *//******************************************************************************/int __FLINT_APImul_l (CLINT f1_l, CLINT f2_l, CLINT pp_l){ CLINT a_l, b_l; CLINTD p_l; int OFL = 0; cpy_l (a_l, f1_l); cpy_l (b_l, f2_l); mult (a_l, b_l, p_l); if (DIGITS_L (p_l) > (USHORT)CLINTMAXDIGIT) /* Overflow ? */ { ANDMAX_L (p_l); /* Reduction modulo Nmax+1 */ OFL = E_CLINT_OFL; } cpy_l (pp_l, p_l); /* Purging of variables */ PURGEVARS_L ((3, sizeof (a_l), a_l, sizeof (b_l), b_l, sizeof (p_l), p_l)); ISPURGED_L ((3, sizeof (a_l), a_l, sizeof (b_l), b_l, sizeof (p_l), p_l)); return OFL;}/******************************************************************************//* *//* Function: Squaring *//* Syntax: int sqr_l (CLINT f_l, CLINT pp_l); *//* Input: f_l (Factor) *//* Output: pp_l (Square) *//* Returns: E_CLINT_OK : Everything O.K. *//* E_CLINT_OFL: Overflow *//* *//******************************************************************************/int __FLINT_APIsqr_l (CLINT f_l, CLINT pp_l){ CLINT a_l; CLINTD p_l; int OFL = 0; cpy_l (a_l, f_l); sqr (a_l, p_l); if (DIGITS_L (p_l) > (USHORT)CLINTMAXDIGIT) /* Overflow ? */ { ANDMAX_L (p_l); /* Reduction modulo Nmax+1 */ OFL = E_CLINT_OFL; } cpy_l (pp_l, p_l); /* Purging of variables */ PURGEVARS_L ((2, sizeof (a_l), a_l, sizeof (p_l), p_l)); ISPURGED_L ((2, sizeof (a_l), a_l, sizeof (p_l), p_l)); return OFL;}#if !defined FLINT_ASM/******************************************************************************//* *//* Function: Integer Division *//* Syntax: int div_l (CLINT d1_l, CLINT d2_l, CLINT quot_l, CLINT rem_l); *//* Input: d1_l (Dividend), d2_l (Divisor) *//* Output: quot_l (Quotient), rem_l (Remainder) *//* Returns: E_CLINT_OK : Everything O.K. *//* E_CLINT_DBZ: Division by Zero *//* *//******************************************************************************/int __FLINT_APIdiv_l (CLINT d1_l, CLINT d2_l, CLINT quot_l, CLINT rem_l){ register clint *rptr_l, *bptr_l; CLINT b_l; clint r_l[2 + (CLINTMAXDIGIT << 1)]; /* Allow double long remainder + 1 digit */ clint *qptr_l, *msdptrb_l, *msdptrr_l, *lsdptrr_l; USHORT bv, rv, qhat, ri, ri_1, ri_2, bn, bn_1; ULONG right, left, rhat, borrow, carry, sbitsminusd; unsigned int d = 0; int i; cpy_l (r_l, d1_l); cpy_l (b_l, d2_l); if (EQZ_L (b_l)) { PURGEVARS_L ((1, sizeof (r_l), r_l)); ISPURGED_L ((1, sizeof (r_l), r_l)); return E_CLINT_DBZ; /* Division by Zero */ } if (EQZ_L (r_l)) { SETZERO_L (quot_l); SETZERO_L (rem_l); PURGEVARS_L ((1, sizeof (b_l), b_l)); ISPURGED_L ((1, sizeof (b_l), b_l)); return E_CLINT_OK; } i = cmp_l (r_l, b_l); if (i == -1) { cpy_l (rem_l, r_l); SETZERO_L (quot_l); PURGEVARS_L ((2, sizeof (b_l), b_l, sizeof (r_l), r_l));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -