1 #if !defined HAVE_NORMAL_SOLVEQUADRATIC_H__ 2 #define HAVE_NORMAL_SOLVEQUADRATIC_H__ 3 // This file is part of the FXT library. 4 // Copyright (C) 2010 Joerg Arndt 5 // License: GNU General Public License version 3 or later, 6 // see the file COPYING.txt in the main directory. 7 8 9 #include "bits/revgraycode.h" 10 #include "bits/graycode.h" 11 #include "fxttypes.h" // ulong 12 13 normal_solve_reduced_quadratic(ulong c)14inline ulong normal_solve_reduced_quadratic(ulong c) 15 // Solve x^2 + x = c 16 // Must have: trace(c)==0, i.e. parity(c)==0 17 // Return one solution x, the other solution equals 1+x, 18 // that is, the complement of x. 19 { 20 return inverse_rev_gray_code(c); 21 // return inverse_gray_code(c) >> 1; 22 // return inverse_gray_code(c >> 1 ); 23 } 24 // ------------------------- 25 normal_solve_reduced_quadratic_q(ulong c,ulong & x)26inline ulong normal_solve_reduced_quadratic_q(ulong c, ulong &x) 27 // Return t, the trace of c. 28 // If t==0 then x^2 + x = c is solvable 29 // and a solution is written to x. 30 { 31 x = inverse_gray_code(c); 32 ulong t = ( x & 1 ); 33 x >>= 1; // immaterial if t==1, but avoid branch 34 return t; 35 } 36 // ------------------------- 37 38 39 #endif // !defined HAVE_NORMAL_SOLVEQUADRATIC_H__ 40