- - - --

Tuesday, September 20, 2011

Re: [p-c] Numbers as Order Strings in Persian

\newcommand{\adadi}[1]{%
\expandafter\@adadi\csname c@#1\endcsname%
}
\newcommand{\@adadi}[1]{%
\xepersian@numberstring{#1}\xepersian@yekanii{صفر}{}%
}
\let\adadinumeral\@adadi%
\def\xepersian@numberoutofrange#1#2{%
\PackageError{xepersian}{The number `#1' is too large %
to be formatted using xepersian}{The largest possible %
number is 999,999,999.}%
}
\def\xepersian@numberstring#1#2#3#4{%
\ifnum\number#1<\@ne%
#3%
\else\ifnum\number#1<1000000000 %
\expandafter\xepersian@adadi\expandafter{\number#1}#2%
\else%
\xepersian@numberoutofrange{#1}{#4}%
\fi\fi%
}
\def\xepersian@adadi#1#2{%
\expandafter\xepersian@@adadi%
\ifcase%
\ifnum#1<10 1%
\else\ifnum#1<100 2%
\else\ifnum#1<\@m 3%
\else\ifnum#1<\@M 4%
\else\ifnum#1<100000 5%
\else\ifnum#1<1000000 6%
\else\ifnum#1<10000000 7%
\else\ifnum#1<100000000 8%
\else9%
\fi\fi\fi\fi\fi\fi\fi\fi %
\or00000000#1% case 1: Add 8 leading zeros
\or0000000#1% case 2: Add 7 leading zeros
\or000000#1% case 3: Add 6 leading zeros
\or00000#1% case 4: Add 5 leading zeros
\or0000#1% case 5: Add 4 leading zeros
\or000#1% case 6: Add 3 leading zeros
\or00#1% case 7: Add 2 leading zeros
\or0#1% case 8: Add 1 leading zero
\or#1% case 9: Add no leading zeros
\or%
\@nil#2%
\fi%
}
\def\xepersian@@adadi#1#2#3#4#5#6#7\or#8\@nil#9{%
\ifnum#1#2#3>\z@
\xepersian@milyoongan#1#2#3%
\ifnum#7>\z@\ifnum#4#5#6>\z@\ و \else\ و \fi\else\ifnum#4#5#6>\z@\ و \fi\fi%
\fi%
\ifnum#4#5#6>\z@%
\xepersian@sadgan#4#5#6{#1#2#3}{#4#5}\xepersian@yekani%
\ifnum#4#5#6>\@ne‌\fi%
هزار%
\ifnum#7>\z@\ و \fi%
\fi%
\xepersian@sadgan#7{#4#5#6}1#9%
}
\def\xepersian@milyoongan#1#2#3{%
\ifnum#1#2#3=\@ne%
\xepersian@sadgan#1#2#301\xepersian@yekaniii%
‌%
میلیون%
\else%
\xepersian@sadgan#1#2#301\xepersian@yekanii%
‌%
میلیون%
\fi%
}
\def\xepersian@sadgan#1#2#3#4#5#6{%
\ifnum#1>\z@%
\ifnum#4#1>\@ne\xepersian@yekaniv#1\fi%
صد%
\ifnum#2#3>\z@\ و \fi%
\fi%
\ifnum#2#3<20%
\ifnum#5#2#3>\@ne#6{#2#3}\fi%
\else%
\xepersian@dahgan#2%
\ifnum#3>\z@\ و \xepersian@yekani#3\fi%
#60%
\fi%
}
\def\xepersian@yekani#1{%
\ifcase#1\@empty\or یک\or دو\or سه\or چهار\or پنج\or شش%
\or هفت\or هشت\or نه\or ده\or یازده\or دوازده\or سیزده%
\or چهارده\or پانزده\or شانزده\or هفده%
\or هجده\or نوزده\fi%
}
\def\xepersian@yekanii#1{%
\ifcase#1\@empty\or یک\else\xepersian@yekani{#1}\fi%
}
\def\xepersian@yekaniii#1{%
\ifcase#1\@empty\or یک\else\xepersian@yekani{#1}\fi%
}
\def\xepersian@yekaniv#1{%
\ifcase#1\@empty\or\or دوی\or سی\or چهار\or پان\or شش%
\or هفت\or هشت\or نه\fi%
}
\def\xepersian@dahgan#1{%
\ifcase#1\or\or بیست\or سی\or چهل%
\or پنجاه\or شصت\or هفتاد\or هشتاد%
\or نود\fi%
}
\newcommand{\tartibi}[1]{%
\expandafter\@tartibi\csname c@#1\endcsname%
}
\newcommand{\@tartibi}[1]{%
\xepersian@numberstring@tartibi{#1}\xepersian@tartibi{صفرم}{م}%
}
\let\tartibinumeral\@tartibi%
\def\xepersian@numberstring@tartibi#1#2#3#4{%
\ifnum\number#1<\@ne%
#3%
\else\ifnum\number#1<1000000000 %
\expandafter\xepersian@adadi@tartibi\expandafter{\number#1}#2%
\else%
\xepersian@numberoutofrange{#1}{#4}%
\fi\fi%
}
\def\xepersian@adadi@tartibi#1#2{%
\expandafter\xepersian@@adadi@tartibi%
\ifcase%
\ifnum#1<10 1%
\else\ifnum#1<100 2%
\else\ifnum#1<\@m 3%
\else\ifnum#1<\@M 4%
\else\ifnum#1<100000 5%
\else\ifnum#1<1000000 6%
\else\ifnum#1<10000000 7%
\else\ifnum#1<100000000 8%
\else9%
\fi\fi\fi\fi\fi\fi\fi\fi %
\or00000000#1% case 1: Add 8 leading zeros
\or0000000#1% case 2: Add 7 leading zeros
\or000000#1% case 3: Add 6 leading zeros
\or00000#1% case 4: Add 5 leading zeros
\or0000#1% case 5: Add 4 leading zeros
\or000#1% case 6: Add 3 leading zeros
\or00#1% case 7: Add 2 leading zeros
\or0#1% case 8: Add 1 leading zero
\or#1% case 9: Add no leading zeros
\or%
\@nil#2%
\fi%
}
\def\xepersian@@adadi@tartibi#1#2#3#4#5#6#7\or#8\@nil#9{%
\ifnum#1#2#3>\z@
\xepersian@milyoongan@tartibi#1#2#3%
\ifnum#7>\z@\ifnum#4#5#6>\z@\ و \else\ و \fi\else\ifnum#4#5#6>\z@\ و \fi\fi%
\fi%
\ifnum#4#5#6>\z@%
\xepersian@sadgan#4#5#6{#1#2#3}{#4#5}\xepersian@yekani%
\ifnum#4#5#6>\@ne ‌\fi%
هزار%
\ifnum#7>\z@\ و \fi%
\fi%
\xepersian@sadgan@tartibi#7{#4#5#6}1#9%
}
\def\xepersian@milyoongan@tartibi#1#2#3{%
\ifnum#1#2#3=\@ne%
\xepersian@sadgan@tartibi#1#2#301\xepersian@yekaniii%
‌%
میلیون%
\else%
\xepersian@sadgan#1#2#301\xepersian@yekanii%
‌%
میلیون%
\fi%
}
\def\xepersian@sadgan@tartibi#1#2#3#4#5#6{%
\ifnum#1>\z@%
\ifnum#4#1>\@ne\xepersian@yekaniv#1\fi%
صد%
\ifnum#2#3>\z@\ و \fi%
\fi%
\ifnum#2#3<20%
\ifnum#5#2#3>\@ne\ifnum#1#2#3#4#5=10001 اول\else#6{#2#3}\fi\fi%
\else%
\xepersian@dahgan#2%
\ifnum#3>\z@\ و \xepersian@yekanv#3\fi%
#60%
\fi%
}
\def\xepersian@tartibi#1{%
\ifcase#1م\or یکم\or دوم\or سوم\or چهارم%
\or پنجم\or ششم\or هفتم\or هشتم\or نهم%
\or دهم\or یازدهم\or دوازدهم\or سیزدهم%
\or چهاردهم\or پانزدهم\or شانزدهم%
\or هفدهم\or هجدهم\or نوزدهم\fi%
}
\def\xepersian@yekanv#1{%
\ifcase#1\@empty\or یک\or دو\or سو\or چهار\or پنج\or شش%
\or هفت\or هشت\or نه\or ده\or یازده\or دوازده\or سیزده%
\or چهارده\or پانزده\or شانزده\or هفده%
\or هجده\or نوزده\fi%
}
Here is my implementation. Unfortuntately, TeX is not good at this unlike other programming languages. If you give 999,999,999,9 to TeX as a number, it complain that it is too big. That is not the whole story; TeX has many limitations in computation as an example in TeX 0.4pt times 10 is not equal to 4pt. If you do not believe me, you can try this:

\dimen0=0.4pt
\multiply \dimen0 by 10
\the\dimen0

On Wed, Sep 21, 2011 at 12:53 AM, Saeed Rasooli <saeed.gnu@gmail.com> wrote:
Vafa: Python's integer has no limit, the only limit is system resources (specially RAM)
(type "int" has limit, but there is type "long" without limit, and python itself converts int to long if necessery, and you have not to take care of that absolutely. That's because I say no limit)
Anyway I meant you to see the algorithm (not the syntax).


On Tue, Sep 20, 2011 at 6:55 PM, VAFA KHALIGHI <vafaklg@gmail.com> wrote:
Thanks for sharing your code. I have implemented it in XePersian which uses TeX macro language and there is no way that you can compare limited TeX macro language with python or C. TeX is not even a programming language; it is just a typesetting language. My code can convert integers between 0 and 999,999,999. What about yours?


On Wed, Sep 21, 2011 at 12:19 AM, Saeed Rasooli <saeed.gnu@gmail.com> wrote:
I previously wrote Python and C++ codes to do that conversion (see attached file)


On Tue, Sep 20, 2011 at 5:19 PM, Milad khajavi <khajavi@gmail.com> wrote:
Just remember that اول is Arabic word that entered in Persian language (واژهٔ دخیل).
In Arabic: اول، ثانی، ثالث، رابع
In Persian: یکم، دوم، سوم، چهارم
Because of the use of 'Arabic words in Persian' (واژگان دخیل عربی در فارسی) is common, numerating with اول، دوم، سوم is also true.

On Tue, Sep 20, 2011 at 4:34 PM, VAFA KHALIGHI <vafaklg@gmail.com> wrote:
ُThanks. I decided to go with اول for First and for numbers like 101, صد و یکم.


On Tue, Sep 20, 2011 at 9:10 PM, Milad khajavi <khajavi@gmail.com> wrote:

On Tue, Sep 20, 2011 at 3:02 PM, VAFA KHALIGHI <vafaklg@gmail.com> wrote:
Which one is right?

First => اول or یکم
Both of them is true.
 
101th => صد و یکم or صد و اول
 صد و یکم 

--
http://groups.google.com/group/persian-computing



--
Milad Khajavi
http://lincafe.wordpress.com
I tried to change the world, but I couldn't find the source code.





--
Milad Khajavi
http://lincafe.wordpress.com
I tried to change the world, but I couldn't find the source code.





--
http://groups.google.com/group/persian-computing

0 comments:

Post a Comment