1 /*
2  *  $Id: hindo.c,v 1.3 2001/06/14 18:15:55 ura Exp $
3  */
4 
5 /*
6  * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
7  * This file is part of FreeWnn.
8  *
9  * Copyright Kyoto University Research Institute for Mathematical Sciences
10  *                 1987, 1988, 1989, 1990, 1991, 1992
11  * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
12  * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992
13  * Copyright FreeWnn Project 1999, 2000
14  *
15  * Maintainer:  FreeWnn Project   <freewnn@tomo.gr.jp>
16  *
17  * This program is free software; you can redistribute it and/or modify
18  * it under the terms of the GNU General Public License as published by
19  * the Free Software Foundation; either version 2 of the License, or
20  * (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
30  */
31 
32 /*
33                                                 ���� 9/1/89
34 
35         a�������, b�Ჾ���١ʶ������������ˤΤȤ�
36 
37         b��[a��x]��2(x��1) where x��[( sqrt(1��2a)��1 )��2]
38         �ʷ׻���̤�126��ۤ�������126�Ȥ��롣��
39 
40         (min)a��(b��2y)(y��1)         where y��[b��4]
41         (mid)a��(b��2y)(y��1)��[y��2] where y��[b��4]
42         ��b��126�Ȥ��롣��
43 
44         ������[ ]�ϥ���������
45         b��Ϳ���Ƥ�a�ο�¬�ͤˤ��������ꡢ(min)a�ȤϤ��κǾ��͡�
46         (mid)a�Ϥ��������
47         b��4 �ʤ顢(min)a��(mid)a��b
48 
49         �����٤�b�ΤȤ������٤ι����γ�Ψ�� 1 / ([b��4]��1)
50         â�� b��0�λ��ϡ����ٹ�����Ψ 0
51 
52 
53          a == -1 <==> b == 0x7f = 127;
54         ���λ������Υ���ȥ꡼�ϡ��Ѵ��˷褷���Ѥ����ʤ�
55         (�����ȥ����Ȥ���Ƥ���)���Ȥ�ɽ����
56                         9/1/89 H.T.
57 */
58 
59  /** ����������ʿ�����ؿ���â������<0�λ��Υ��顼�����å��Ϥʤ���0���֤��ˡ�*/
60 static int
isqrt(int i)61 isqrt(int i)
62 {
63 	register int a, b;
64 
65 	if (i <= 0)
66 		return (0);
67 
68 	for (a = i, b = 1; b <<= 1, a >>= 2;);
69 
70 	while ((a = i / b) < b)
71 		b = (b + a) >> 1;
72 
73 	return (b);
74 }
75 
76  /** ������a��������b */
77 int
asshuku(int hin)78 asshuku(int hin)
79 {
80 	register int c;
81 
82 	if (hin == -1)
83 		return (127);
84 	if (hin <= 4)
85 		return (hin);
86 	/* ��Ⱦ������0�����ꤷ�ƤΥ��ԡ��ɥ��åס�motoni1,2�Ǥ�Ʊ�� */
87 
88 	c = (isqrt((hin <<= 1) + 1) + 1) & ~1;
89 	c += hin / c - 2;
90 
91 	return (c < 126 ? c : 126);
92 }
93 
94  /** ������b��������(min)a */
95 /*
96 int
97 motoni1(int hin)
98 {
99         register int    c;
100 
101         if(hin == 127) return(-1);
102         if(hin <= 4) return(hin);
103         c = hin >> 2;
104         return( (hin - (c << 1)) * (c + 1) );
105 }
106 */
107 
108  /** ������b��������(mid)a */
109 int
motoni2(int hin)110 motoni2(int hin)
111 {
112 	register int c;
113 
114 	if (hin == 127)
115 		return (-1);
116 
117 	if (hin <= 4)
118 		return (hin);
119 
120 	c = hin >> 2;
121 
122 	return ((hin - (c << 1)) * (c + 1) + (c >> 1));
123 }
124