Initial git import
[sxemacs] / tests / automated / format-tests.el
1 ;;;  format-tests.el -- Tests for formatted output
2 ;;
3 ;; Copyright (C) 2007 Sebastian Freundt
4 ;;
5 ;; Author: Sebastian Freundt <hroptatyr@sxemacs.org>
6 ;; Keywords: tests
7 ;;
8 ;; This file is part of SXEmacs.
9 ;;
10 ;; SXEmacs is free software: you can redistribute it and/or modify it
11 ;; under the terms of the GNU General Public License as published by the
12 ;; Free Software Foundation, either version 3 of the License, or (at your
13 ;; option) any later version.
14
15 ;; SXEmacs is distributed in the hope that it will be
16 ;; useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 ;; General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>. 
22 ;;
23 ;;; Synched up with: Not in FSF.
24 ;;
25 ;;; Commentary:
26 ;; - test for conceptionally correct arithmetic
27 ;; See test-harness.el for instructions on how to run these tests.
28
29 (eval-when-compile
30   (condition-case nil
31       (require 'test-harness)
32     (file-error
33      (push "." load-path)
34      (when (and (boundp 'load-file-name) (stringp load-file-name))
35        (push (file-name-directory load-file-name) load-path))
36      (require 'test-harness))))
37
38 ;;-----------------------------------------------------
39 ;; Testing numbers
40 ;;-----------------------------------------------------
41
42 (Assert (equal (format "%d" 2) "2"))
43 (Assert (equal (format "%d" -2) "-2"))
44 (Assert (equal (format "%2.2E" -2) "-2.00E+00"))
45
46 (Assert (equal (format "%\0s" 'a) "a"))
47
48 (Assert (equal (format "%x" 100) "64"))
49 (Assert (equal (format "%#x" 100) "0x64"))
50 (Assert (equal (format "%X" 122) "7A"))
51 (Assert (equal (format "%.4X" 122) "007A"))
52 (Assert (equal (format "%4o" 100) " 144"))
53 (Assert (equal (format "%x" 10.58) "a"))
54 (Assert (equal (format "%o" 10.58) "12"))
55 (Assert (equal (format "%#o" 10.58) "0o12"))
56
57 (Assert (equal (format "%#8x" 1) "     0x1"))
58 (Assert (equal (format "%#+8x" 1) "    +0x1"))
59 (Assert (equal (format "%#08x" 1) "0x000001"))
60 (Assert (equal (format "%#+08x" 1) "+0x00001"))
61 (Assert (equal (format "%# 08x" 1) " 0x00001"))
62 (Assert (equal (format "%#.8x" 1) "0x00000001"))
63 (Assert (equal (format "%#+.8x" 1) "+0x00000001"))
64 (Assert (equal (format "%#+ .8x" 1) "+0x00000001")) ;; plus has precedence
65 (Assert (equal (format "%# .8x" 1) " 0x00000001"))
66
67 ;; floats
68 (let ((forms
69        '(1.0 1.00000 0.5 0.005 5.000005 4.0625 8.03125
70              9876.54321 10000.00001 12004.40021
71              1.5e+10 1.125e+11 1.0703125e+12
72              1.1e+15 1.2e+16 1.4e+20 1.45e+24
73              1.52e+28 1.55e+30 1.52105432e+31 1.5445633221e+32
74              1.7777777777777e+33 1.7777777777777776e+33
75              1.8999999999999e+33 1.999989999999999e+33
76              1.99999999e+35 1.9999999999e+36 1.999999999999e+37
77              1.99999999999999e+38 1.999999999999999e+39
78              1.9999999999999999e+40 2.000000000000000000e+40
79              2.000000000000001e+42 2.000000000000009e+44
80              2.002000200002000002000000e+48
81              2.000000200000200002000200e+50
82              200000020000020000200020.0e+50
83              12345555555555555555.999999999e+60
84              12344444444444444444.999999999e+60
85              1234545454545454545454545454545.000
86              123454545454545454545454545454545454545454545.000
87              4444444444444.55555555555e+100
88              5555555555555.55555555555e+102
89              5555555555555.44444444444e+104
90              5555555555555.99999999998e+106
91              50505050505050505050505.0e+200
92              1e+300 1e+301 1e+302 -1e+300 -1e+301 -1e+302
93              1e+304 -1e+304 1e+305 -1e+305 1e+306 -1e+306
94              1e+307 2e+307 8e+307 -8e+307
95              1e+308 -1e+308 8e+308 -8e+308
96              1e+309 -1e+309 -8e+309 8e+309
97              ;; we should be outta range of double floats
98              1.00e+310 2.50e+310 2.55e+310
99              2.125e+312 2.0004500045e+313 1.2e+314 1.2e+320
100              1.22229e+320 100e+320 101e+321 102e+322
101              ;; we're still alive?
102              most-positive-float most-negative-float
103              ;; the following two may not work correctly if the number
104              ;; distribution has many subnormal numbers
105              ;;(1+ most-positive-float) (1- most-negative-float)
106              ;;(1- most-positive-float) (1+ most-negative-float)
107              1.0e+340 1.0e+350 1.0e+380 1.0e+400
108              1.2e+300 1.2e+310 1.2e+320 1.2e+400
109              1.2e+2000 1.2e+3000 1.2e+4000 1.2e+5000))
110        (failures
111         ;; known errors (due to precision issues, not SXE's fault)
112         '(1e-300 1e-301 1e-302 1e-303 1e-304 1e-305 1e-306
113                  1e-307 1e-308 1e-309
114                  2.5e-310 2.55e-311 2.55e-312
115                  1.2e-320 1.201e-320 1.25e-320
116                  1.22229e-320 100e-306 100e-307 100e-308 100e-309
117                  100e-310 100e-311 100e-312 100e-313 100e-314 100e-315
118                  100e-316 100e-317 100e-318 100e-319 100e-320 100e-321
119                  100e-322 100e-323 100e-324 100e-325 100e-326 100e-327
120                  100e-328 100e-329 100e-330 1.2e-330 1.25e-330
121                  0.5e-306 0.5e-307 0.5e-308 0.5e-309 0.5e-310 0.5e-311
122                  0.5e-312 0.5e-313 0.5e-314 0.5e-315 0.5e-316 0.5e-317
123                  0.5e-318 0.5e-319 0.5e-320 0.5e-321 0.5e-322 0.5e-323)))
124   (mapc-internal
125    #'(lambda (str)
126        (unless (or (infinityp (eval str)) (zerop (eval str)))
127          (eval `(Assert (= (read (format "%f" ,str)) ,str)))
128          (eval `(Assert (eql (read (format "%f" ,str)) ,str)))))
129    forms)
130   (mapc-internal
131    #'(lambda (str)
132        (unless (or (infinityp (eval str)) (zerop (eval str)))
133          (eval `(Assert (not (= (read (format "%f" ,str)) ,str))))
134          (eval `(Assert (not (eql (read (format "%f" ,str)) ,str))))))
135    failures))
136
137 ;; now testing bigz formatting
138 (when (featurep 'bigz)
139   (let ((forms
140          '((("%Z" 2) . "2")
141            (("%2Z" 2) . " 2")
142            (("%2Z" 200) . "200")
143            (("%+Z" 2) . "+2")
144            (("%+4Z" 2) . "  +2")
145            (("% Z" 2) . " 2")
146            (("%Z" -2) . "-2")
147            (("% Z" -2) . "-2")
148            (("%+Z" -2) . "-2")
149            (("%-4Z" 2) . "2   ")
150            (("%.2Z" 2) . "02")
151            (("%4.2Z" 2) . "  02")
152            (("%04.2Z" 2) . "  02")
153            (("%-4.2Z" 2) . "02  ")
154            (("%0-4.2Z" 2) . "02  ")
155            (("%Z" (factorial 20)) .
156             "2432902008176640000")
157            (("%40Z" (factorial 20)) .
158             "                     2432902008176640000")
159            (("%-40Z" (factorial 20)) .
160             "2432902008176640000                     ")
161            (("%.40Z" (factorial 20)) .
162             "0000000000000000000002432902008176640000")
163            (("%040Z" (factorial 20)) .
164             "0000000000000000000002432902008176640000")
165            (("%.8Z" (factorial 20)) .
166             "2432902008176640000")
167            (("%08Z" (factorial 20)) .
168             "2432902008176640000")
169            (("%24.8Z" (factorial 20)) .
170             "     2432902008176640000")
171            (("%36.28Z" (factorial 20)) .
172             "        0000000002432902008176640000")
173            (("%036.28d" (factorial 20)) .
174             "        0000000002432902008176640000")
175            (("%0-36.28d" (factorial 20)) .
176             "0000000002432902008176640000        ")
177
178            ;; now the same with the %d specifier
179            (("%d" 2) . "2")
180            (("%2d" 2) . " 2")
181            (("%2d" 200) . "200")
182            (("%+d" 2) . "+2")
183            (("%+4d" 2) . "  +2")
184            (("% d" 2) . " 2")
185            (("%d" -2) . "-2")
186            (("% d" -2) . "-2")
187            (("%+d" -2) . "-2")
188            (("%-4d" 2) . "2   ")
189            (("%.2d" 2) . "02")
190            (("%4.2d" 2) . "  02")
191            (("%04.2d" 2) . "  02")
192            (("%-4.2d" 2) . "02  ")
193            (("%0-4.2d" 2) . "02  ")
194            (("%d" (factorial 20)) . "2432902008176640000")
195            (("%40d" (factorial 20)) .
196             "                     2432902008176640000")
197            (("%-40d" (factorial 20)) .
198             "2432902008176640000                     ")
199            (("%.40d" (factorial 20)) .
200             "0000000000000000000002432902008176640000")
201            (("%040d" (factorial 20)) .
202             "0000000000000000000002432902008176640000")
203            (("%.8d" (factorial 20)) . "2432902008176640000")
204            (("%24.8d" (factorial 20)) . "     2432902008176640000")
205            (("%36.28d" (factorial 20)) .
206             "        0000000002432902008176640000")
207            (("%036.28d" (factorial 20)) .
208             "        0000000002432902008176640000")
209            (("%0-36.28d" (factorial 20)) .
210             "0000000002432902008176640000        ")
211
212            ;; testing base converters on big ints
213            ;; oct
214            (("%o" (factorial 20)) . "207033167620255000000")
215            (("%+o" (factorial 20)) . "+207033167620255000000")
216            (("% o" (factorial 20)) . " 207033167620255000000")
217            (("% +o" (factorial 20)) . "+207033167620255000000")
218            (("%+ o" (factorial 20)) . "+207033167620255000000")
219            (("%#o" (factorial 20)) . "0o207033167620255000000")
220            (("%#+o" (factorial 20)) . "+0o207033167620255000000")
221            (("%# o" (factorial 20)) . " 0o207033167620255000000")
222            (("%# +o" (factorial 20)) . "+0o207033167620255000000")
223            (("%#+ o" (factorial 20)) . "+0o207033167620255000000")
224            (("%o" (- (factorial 20))) . "-207033167620255000000")
225            (("%+o" (- (factorial 20))) . "-207033167620255000000")
226            (("% o" (- (factorial 20))) . "-207033167620255000000")
227            (("% +o" (- (factorial 20))) . "-207033167620255000000")
228            (("%+ o" (- (factorial 20))) . "-207033167620255000000")
229            (("%#o" (- (factorial 20))) . "-0o207033167620255000000")
230            (("%#+o" (- (factorial 20))) . "-0o207033167620255000000")
231            (("%# o" (- (factorial 20))) . "-0o207033167620255000000")
232            (("%# +o" (- (factorial 20))) . "-0o207033167620255000000")
233            (("%#+ o" (- (factorial 20))) . "-0o207033167620255000000")
234            ;; hex
235            (("%x" (factorial 20)) . "21c3677c82b40000")
236            (("%+x" (factorial 20)) . "+21c3677c82b40000")
237            (("% x" (factorial 20)) . " 21c3677c82b40000")
238            (("% +x" (factorial 20)) . "+21c3677c82b40000")
239            (("%+ x" (factorial 20)) . "+21c3677c82b40000")
240            (("%#x" (factorial 20)) . "0x21c3677c82b40000")
241            (("%#+x" (factorial 20)) . "+0x21c3677c82b40000")
242            (("%# x" (factorial 20)) . " 0x21c3677c82b40000")
243            (("%# +x" (factorial 20)) . "+0x21c3677c82b40000")
244            (("%#+ x" (factorial 20)) . "+0x21c3677c82b40000")
245            (("%x" (- (factorial 20))) . "-21c3677c82b40000")
246            (("%+x" (- (factorial 20))) . "-21c3677c82b40000")
247            (("% x" (- (factorial 20))) . "-21c3677c82b40000")
248            (("% +x" (- (factorial 20))) . "-21c3677c82b40000")
249            (("%+ x" (- (factorial 20))) . "-21c3677c82b40000")
250            (("%#x" (- (factorial 20))) . "-0x21c3677c82b40000")
251            (("%#+x" (- (factorial 20))) . "-0x21c3677c82b40000")
252            (("%# x" (- (factorial 20))) . "-0x21c3677c82b40000")
253            (("%# +x" (- (factorial 20))) . "-0x21c3677c82b40000")
254            (("%#+ x" (- (factorial 20))) . "-0x21c3677c82b40000")
255            ;; test overflow
256            (("%Z" (factorial 120)) . "6689502913449127057588118054090372586752746333138029810295671352301633557244962989366874165271984981308157637893214090552534408589408121859898481114389650005964960521256960000000000000000000000000000")
257            (("%Z" (factorial 4000)) . "18288019515140650133147431755739190442173777107304392197064526954208959797973177364850370286870484107336443041569285571754672461861543557333942615617956996716745284831597317498818760937482804980419576512948720610558928129788097800620593429537705326740624453884285091743951756746144447362378722469436194575929579900114212973360658998073977714697261205048663725936337490404066097966637170254021348800944280342285355946649681316260163459743803577175903394733170076841764779082166891184529324230033414145497801832598218518406552257097392530024582738982919104406782168708871495603501905867399966298798534877747923179195791416504408054878974770308650707120878837624986576073340449414854578367383301715706358194127400849855604080473305196833482408079420964275187538889115296655522397723924887154624810659788321005620558369604778657904771918388054319251513981954296741688447246185021250402225010116433016818588036690180177691461779713104301640395708274734701186772756966064611023656528765138735704190876200697145804692125236821066805337175220605745377557452592208653939853278523841448314026548802309860391087939783218946129582647928430739985554883806198749831633640196211202756086016039171607744078776876219661603702759454887945247605749205543464095883664514960293873244842409803801480566600124415293789831496309554117113888561569494314926134470477513516416560102984058751906208865570183683850791317395702861350821464653600469443279077733978568711404244774089509216727922510660941411716412467443445414001188915966547283773988670739792818897314762082568914041952211779194055311405259158538932388745292324386826830135904886472292289993848482289254307628467614523292519222687689180219788377184005246290896703260524910362136627321135976515358528150143796798116836263053229733971612275184896139539613129329008449214723196703789119820971205922195513915546814704778682373487718946560822811623038853887054357316290622378472322045316639418491798517077275839637525427601452961835674484434498885698840692468550825765131610925966585339561854456154229048295742274725126218799745448031391826295221114381890600683208441558088271228618006589059444108806652992787854634497487158675770983422610936590600627170500972481399444145398522756870626097250230229195799277299921844954715690883242553569256657132515663544931830393317518828986443942138971609142621397646808351809694603734872977984148002699965137870448199866167162949256435040416146886823942144459105175033488395869910405207521329016842673168563837531518918339627724066152933627236730561155418227888673513937454508103826102827706121560330906016404162420051373313654570111102003319577878502216919170112074608722852376799943191590480651623958062982829452035227119036502426583752512199824089725611711059153935434418985109241404135069047109527514730648502064630431371185922523036941621026392783813435540195800531988645430344745298845640017082732623248838473771603478336326662579219137601422632057648758807935233915527562817942378675243919886800056209434731407685691942327092464101136254795499159351103542747723434544436366313104996373661654989465498180892716462805042227038222104784062626027480151567377841821316292095295686368619300417863327530764301323081902435971165925163513225511176258919471673437553320934916910573999020966087207663133871516530391787535755420348174519954013015999193335205032571176460105005716115305748669364682675265014310223271762807620242805617435594927890676408953057384890719681225840400396698155624793888816156585043604782961704971397764959404751358445856914581957186533573207690355894150776647727994156425641953755517727965486096675384222232344185537279888780570854092084221993660761154788359777439798490851148031275123759286793224660188593768897291749180357297185650430735063126035278321749629995702200115722386600046772883018963166273463715186812543356173550341233310175600817771447170656517505385258772069067139665478506263898380526394388218036388768999161538645432932116471146392562992204259450889291928261780531925618148311151259088519869787637913607866079920830781433275298468534248595471485354420794089854693167644320115900404444471266030942746376074187982809857292874382829734306879420308783010740784767155894363033186129183748698373599293267795620690003900348542140553208244771165593739117369452474295075445169488356550100854423929030967163401348223503674045821834526710830392520955478859202303175309815706259592416130388770535449570146586161954289529234209342432075461261173246383180702862172009624828852517861214008242944903162464816939278645210656431141653019224783906038062818006434258491952705341708781231767324026544165240012431457995565227331912056216396141277926932316783631899833106810492890045890947294731794016389385348294079360921757589715698098491612254898203787546124091057862387229987442131738499764391062422228395736099751277880661280909246369674792326056952220508861243875642482808175793303703933394191224832165950388337931626643339913192088808753619030386928808349931733881036690498513779587801764477865791351420222949860738228995728065763459283625096944678593378349990211317403358327367677358882377095918185840441346045760435580063918587956888086127034558064154832456098224664532422114583653763989534559801683261113731162039500068729224661509382267286483841867542303955164213391663536072749966590737898408144092699675796793165775891429992491955485860639629542416955757565163223827874193321274119938618709482020627749094917473754346320653165690129809741806883246764053966717253521140010801409998318494470531219051920354752556183478378238398583402765337923843167749738355049636714529840534145950376598809459294819192486096200503652538835417613002983933634477053826438814791235363934440952835213240806543802505241445900981152753843778634021300832293332432473400040109754281828950625464331409151961292319287863535740382445771128522343533054993071872524564127962306298218521662304206610010638488461150361786151832595182055013210238035059473479841417644445066550217093994746959565730463201996845756999575031950401331385688683576883429289274419202816101239071817771853612534620088858074904095239406471009098851796038360101243053736361346640211872570375441319261567131238168652234864182359667285536913841122976956009892970909409178865928472056691904571596961458646895132972589012090613887584436018692038947475932753085268106507554394567201654757930957224629573401948677157237825005540282635839895509019254240256916422227590032685003087320017232658420681209681389364174854034319152111706246564733896551636271748411627920466475472421243033805492052542237647091252577811952376244836844025673570936216945539206875730684120187779664758451508678786539887154966732995692212544207529457534936853900663520665102592278581210192104846016594846265525000394264201946315492667174670489454576610993722063668720936949698308641684437046485292906040368218708947194882991333823400676584552108673913669306118549159369734833071319506680872661886898225398171896329288732499509337836463164384614967690283284184136334006184670970038275153458133098776493171693249836721707632973537518273692928527497068121779606865163943692606596848941143683627629169873171114739189794632775706536177409526869936538136348369630762610163490694986911903178859927739423796596582439105912599204583810744740479342404550513976713360591833475711496976836332005885151231030818986389033126325119226309584818058301429763149472903925739659774337307109687940297813700796873400566095281249251559137923743113469044584820584542770746490047535898370961450995287930441328833542933636539386097851378739174078158132593877463567524868470795313740375647059352650583871001646082364842709333314532933141725314262510333047099681128329792983694287727106008519184538377065089964546579000542260452715147077137452076302879112802094308224402060706282308208678850263037733351444756065285721900833083634023860920356321356382318484421995141074387149942542550133039926139155010190614633196727199469768170121209097613598302048321148497175007150184555423280152476407230065108963493864309805262458731715886593175689747530567359088332598961192319881186961400055356294945140450806114214490420494488195417136403967132286869444062615622815233336396279517485469862880809956041938378161336156979526713793454354319018535526139196959277008828634440008764782171726908279132449346924807112458895951881542382952497102061566169481361027449429416228859029591798532192088531772405831332410104172391828682208239266557146168642210154401086974397003647170356217905465594944933170065175291981240572835024374361017977695084363373226470846255498368067535698751768103817520605779489720985090002595078926475029239124403277040719184010486962844211160986922952144938430963756963408787147933184107904312838985994963982784496688190643908936394858404598837762653245968848299901455260080572627872653099337092686312650606546084656202210845053932679131706841390889951865628810708670194485207654079244417321332232196041180225814997707988397637369268804955010409293139079608620689856756139863786355461818276369292665568749282154818479663283704713663666842236273009790537968973379093662517795316051746410279831975339791651704861188979834156418998505732384020730350075052669695594594753081616632885311572351609352631187129393729557398993321794518158269658073683417584260274184235030846683698193879109933863561435059993549597333514217973995915742796206889856584584493875193805504685107321011420502217815128118404137521250590361329385146997427292035829509205811367395885622247504950811752188165627552137681095618860955664505372763469788466067973748736658759105548049054658237200096293754479296344115915560231138432518248450383276234795400180535655551222536669390799317067896797756236783441752907948891802488298281245615590113512482344591092230909649423933991714557108941323849548468680509335203770970493785006636718394242326057416155509029270066096293813080877339787718442773014833232754755736783313789547145535129557193581885962158684756484475219230828423777756012721234731368785218564362953263092286535139160440838713013861328416662947756104857391740722209360021068158824717926850831589591367302143596625426553706038593255843919505223140871543995210720444637571268651195165483531243799087083070940544241515809139594158704843980567202482856647644447362604252961907705738740354460336586792214638225365973993001974668174157206242597452556046629209551599663117912609702944345176608757619561247872050409609062772362769045711709729061066411540898769707847042980034982033351136308779676287974627667703893888026848748953201438481632037717854462054861859986684636917120883602793194058658599425778515519713798214407689849211487929150179918547200558584524139792439377469676039518101451697712860634235352474290575260172151562129240720796835619967878383018961055921622371480562682714603085506932806187937976625431071742833007749235636990700120567425836156233607547500827789537909071263596294926763891075439575973972560478399510790078797663071024149826759934524980569432847819403219226207098701759952415628476519584752248050578584198211799092030838909208236225141975964892778944163008811179723219354847713753084628828883321692575327835658786892010648865205021985527642612795652759365359359048052205587306960853879351302215329380382709288672566169552660197788055450054177652374955319992805345989662399494012874012278677451052584166987084866267245492968785684175508510910492913793478551456991152291522750377308973310200505007906906671435839262115546753934391579860133029544403932422271218975046896384482252108820546415274174791693426071019927278518520520164621127271231748277979659289204850823018535192067323372368224831050642902153626845618478009622824733150764188329304815843651352730897836727021023023627320228373645802602496000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
258            (("%b" (factorial 4000)) . "1100101100001011001001011100101011011110010001011001110111110101011001010010110110101010111000000111101100010000100001101111110011100001111110100000010100011101111011001100001010001000111111111110110001111011000000010110101110111001000000010100111110010000010110110011011101011000111000111000111000111111001100110100011110101101011000110000100011000001000001100000000110100110000100111101011011111011101101010100100010010010101000011101100001101101100000101111110100011101101111100100101101000111000001001101011110111110110101111001111000001011010000110001001101101100000001100101011000010100110101011111011110110111111000000010100011111111111001010001010001000101001001111011001100001000110011010011101000101110110000000001111000010111101000010001000110000111111111101100110001100110100100110101111011110011001011011000111010010010111111001000010110010001001010111000110101111110101110010101100100101101000111010011100100001011101000100111001110000110001111101101110101111001101100100010101000100001110010011000101001100011001011001000111101110001010001000000000011100100111001001100111110001110000110110000110111111101000110100111111000111001001111011111011111010101100011110000010110010101110110010101111011101000000010110001100001001000101010000101110010011011010010000111100001010100111011011010011110001011110001010111000110110010100110011000001101111100001011110010011000110011010001011000100111001000101011000110101100000000101100110000011010100111011011101110101100100111110100001101100100001000101100100100101111001001101101110010100111001111101111010001110001101010111010011000000110001111011100110000001000010111110100011011111010000100100100110111101001011100100101100111101010011100010111001110000101110111001010000001010110010011001111010110100010111100000111010010110000001111000110000100011111110010000101100010100110010101100110111001101000000110101101001100111101111111111111100010110001100001000001100110000011101000110101100000010001010000010001001000001011111000101011001000100000000000001000111000010010100100010110011110010110101011001110001110001101011001001101101110101110000101110011100101001011001000011011001010010010100101110111111000100110111000101101100000011101011111010010110100110100100001110100000001100010101000110011100101000000000111101011000000011100100101010011111110010000101000100011101011001011100000101001111001011011110110110101010101011100101010000011010011010100100111111001000101111111111101000000011001110000011110101010010100111111101111101011101100100111011010110011001001100111101011111000011010111111010011110100010011011101000100110011001111101100010011010001010001101111110011110111011111111100011100111010001010001010010000101100110001011111011001110010010111000110010010100000100000000011100110001111001011101111001110101010000100001100010001010100010000100000101111001001100011001100001110010010000110001101011101110100110101101000110011000000110010101100010100001010110011101100000101100110010100011100001101001111001001101000110010001110010000001100010110111011011011100010100100111001101000010101000000000110101100101111010011010100110001011000101000101100111100001011101110101001100001110011111100000111000100010101100010100000011001110100001011111011101100000110001110011001010011101110001111011110001100011110100010100101111101001000101000101100011110111100101001101010011001110101100001100100001110111010101011111011110111000000000001111101010010011001000100010010110100111001100101110001100010011101110001111111001101000101000001011111011000110111111100111110110101001011011101111010111010100111110100101001011101010110010010011100101011010101011111001000110110001110101001100010100010011110011100100101010011011110110011010111000111011100110011000001001100100101010010100001111110010001000111001110010100100110101011111001001100001001000011000010011110101000110000000110010010101100000000010010111110000000101101000110100000111001010011110001101100101010010011010010100110001111000011100110110101101001001000101001001010110110110010100011110001111100011010000111001101010001001010010110110101101000000101100101111000000110100000001001100100100101101111001111011001000000110101010101100010000000001000000001001111111000010111010010000101100001101100110010010101101000111110010100101011110011101101010100010100000111100100100111100100111001010011000010010011100101001110010110100001001010010010010100001111010010110000110111110001110001000000011011010100111000011101101000011100111000011000100100001110110100111001111010100000000111010100010101101101010110010000110101111000100110000101101000101010001110101010001101000011000111010111001111100101000010100000110101101000101010111110101001110100001101110100111100010011100011010100011111000010000000111100110010001111000110100011110001100010000110110011111010100001001010000001010110010110111010011000110011000101001001110011110011110001101010011000000001101111010011110111110100010000010111011111111111000111101001110011111010010111110001010101110110010001001100011001010110000100011010100101110101011111110010101000111010001100011100100101111011111101011101100001101010010011111001001001111100101011101110000110110011010010101000000011111101000111000011010110101111110010111101010000001010111110000010011000011011100010010000110000100010001111011100110101111101100010001111011110100110111111110010110000001110111110010010000001101011010101010010010100100000110010011101000111010110110001110001101011010000001101000110000000101010011111110111111001110101011000101000110110000111111000010100011001001001110101001000011111000011100000001001111001000110100101100111010110110011110011101010111100100001111100000110110111111111000101011110111010001000011101100101111001001100100111000111010111100000110100001010101010000000111111100100011011111011000110101101110001001010100111000001011011001001011100101010111001101001101000100111000001011110111000010110111100101111010111100011110000001110100111100000010011001111011010000100000110001100101010100000101001111001100110101110111110001111011100100100000110000000101101011010011000011011100011101110000110000111101011100010010011000111110111101000101010101000011011101010111011010100000110000001101110000100001001010110100101011010111010101010010000110100001111101011111010010011011010011001100101110110001100101100101011101110001100001110100000010000111101011011110100100111010001011101000101011011000000011000011101011111011000011001100100100001010110010110110001110010101101001011001111110100001101011111000100100000100100111101101100001000001101111101000011011101100000011001010101000011001011100111010000110110011011011001111101000011001000001001101110111101111101100011110100011110110011111110111010110011111110100110001000110110101100011110011111001010111000111010100011110110001111011111011101000100001101000010101110011101100001101011000100100111110111101110111111010011000110101011000011100001011100100100110010101001101110101111000000101000111001110101110110110000000011001100111010011100110010000000111011100111010011110100100010101010001100000110001100101110001110011111101110000001111101100111101110000111100100001011000000101100110001001001101111111101001001111101011000001011011010011011101011010001111010010100010110011001110011101001010010011111001110000110100000110100101010010110101100011001101001011010110110001011110010011110100110100111111000111100100101101111000101100111100111100100111110010111110000111001001000000001110010011100000101000110110000111001100000111000111001100011010110100101101110011000110100110101000110101001111100101000100010001110001011001011011001110010010101101110111100101000110101101111101010001011110100100111000000100011010000110100010111100100100111111111010000111100011010001110000100010010001010101000111111101001001011011110101000110010010101111101000000100101100101101010100000111101010111011010011100111101001010011001110011000001110000011111101000001011010110101010101001111001011011110111011110100001111110111000100110101000100111001111001100011100100110101011010001110111100000111000100011101000010010000000111001010000111010110111010110011001110101011000010000001101110011001011101011100010011000001101110101000110110110000101011011011100101111110111110110010101111101101010100001101010001100001110011010010110101111100010111011001000010111101100001000010111010100100010001001110100001010110010100011110110011000111101111110100101001101011001011010100111001000110010110001010011111111000011101001011011111010011110001000000001101000001000010010100111011100000011001110001011011110001010010001100010001100001010100011111101010110111010101101100110001001001001001010100000101001110100000010100011101000111001111001100010101111000011111101100111110101010100000111100011001000101111110110110001011110000101110100011110001110000010000000101001000100010001000010110010011001011110011100111101101100010101111011101000101111010100111000100001000011010010111101100110001101000000110010001000011010000100101010100111100011010010110101100001111011001011000101000010101001011011111011110110010111000000110110111100011000100101010001100110111111001011101011111110111011001000111010000001001011110111111101010001001011001101010000010101101101110000010011110000110111010100001101000100000110010000110011000000010100100001011010010111100100111001000110001010111111011111011001101101100101101011101111001100001010111011110010110100011011111100100111010100001111011011010011111110111010000111110111001000110001100101000001111100101001111101001110101010000100010011111000101010111000101011000100000000001000000010010010010010000101001110011110101000011000000010111001111011000111111101010001111000001010101001101111000101100001100011101000011011000111100000101011011100000001011011101000010011110000101011111110100010101001011001110001101010101001001111001111110110010111111101111001001100110011101011110001101000011010110111100101100110010111001000101011000101101001100111001111101100000110011001000001001111001000100010010110111111010111110001110011011000001101100010010111000100000100100010111100111101001001111101011011110001110111101000001000001100100101000111100010001101011110010100000011010010011100100100111010010100001111111111000001101101010011101111101101011010001000110111110010011010101101011001101100001111100110101000110111100000101101000011011111110110001101110011011011100111001101001001100110110001001101001100001011111011000110010110000111110011001101001011000010111101110001010111100111101011011001001000000000001011011001101011000010100011111010110110110101000011011111010100110001110110011101010010101101010100011000000101011011000101111000011011001001110001001001101110111101011101101111010111001111110011111101100001001011110101110111011111110100001101000000110101101100011110000101010000011100010110100101010101001100000110110001100110011000001101001101001010011100010001100111011010010001110001100001001110101001000111100100001100001101000110010111011101101000001001000011110100011010111110010010001010011000110000101011110101010101001010111011100000101101001001001101101000001011000010000000111110110100000001100000101101110110001100011011100101001001000000110001100001000101011111011100011100110100111110111100101000001010100101011000111011000110100101100111110100111001101010100100101110111101000111001001111101001110000110111100101100011110101011011010001001110000110101011010001101011010011111000101100010101111111110010010000011111001111001011101111010101110111100100100011001110010111001111011011111001000010000110111100000001011110111001010010010001000011001110110010110111000000100000100000011001101010011101100101110010011100100000100110111100110011001001111010111111011001100100000011110010101111000101100100100110110000011111001100011001011100011010010001100011111100101101011110101011001111110001011111011110111110100101110001111110110101001111000000111011110110010101111110000010011010000001110100011010010010100111010100101000111110110001011100111011011000001100011101111101100010000100010011111110010111000101000011011100110100100110010000100110001010110010100010001001001001110111001010110111001101101110110011001100000101101111111110001110011110111100011111110000110100011110010010011100110001100000100110100110101010111111100111010010010110001100101011000100110001100110000010000001110001110100010010001011000010111010100011011111001110111001010011111010000101100001110000111001111100011101111011001100110101001000000110101011001101001001001110111001101011101100010101100110000100111000100001100011111110001101110011101001011101011011110101110000000010010111011111001011100111100101111010001111101000010000110001101100110001001000001100001000001010110101111110010011001111110010011100100001100000111101110001010110010110111101101010011111000000111000101001011111110010111100010101101110011100110000101100100010100001100110001111010111000010100101101110001010000001010110111110011110001100011010000001000100010101001000101101010101111000100011001000000111100000011101110111001101111100101101011100011100000111001110110101010000010000000001111111110111111000011010000011101001000010000100100111011001010100000000001101011110001011111010111101011001111100000110000000111101100010100000010110000000101010000000101100101110111011011100010000111000000010111001001101011110011100111001101111110001101011000111100000011100000000101001001001011100111000010110001010110110011010100000000100100110001101001010011111111001100011010101101010011011010100111000110100100100011100101101111100100101001110001000110010101000110110000101000001001000001011000100010111110100101110000101110100100101001001101001001011111000110101111110011001001000011100111011011100101110011000000000010110101100011001000111010111010000000101110010001101000001101001101011111110110110010011110101010010111001000010001010111100111011010001000011100000100000101111111011000010101100110000001110000011110101111111100000010111000011110000111011101001001001110100110011101000100100111100111001100000100101111110101011010101100110001000100101000001100010101011011010011111100011110001010111011000110100010101100001010101010110111101111010001011000100110111101110101001101100011000011101100100111100101000011011111111110010111111101110000100101001110011111100000001101110010110111100010000110010111001111000111001000001000000001110001101000000110111101111100111110100100111000101101001101011100011101001001011011101011010011101000101001000001111110000001111000001010001011101011110001100011100011011001110101011100010011011101000110011110011101001000101011011110010100101010011000011010011101100100011101011010111001110010001000110111010101110111110100101001111000000011110011100110001011000111111011011001011010110000110010100110001111101010000010101000100100111101111010010111011111111010101000110011011110011010000101110000010110001001100001011111000001011000111000000110100111100000011000001000111001000101010010101001111100011101100011111011011101101011001010101100110011010101101111100101110000010100011100010101010101001010010011101110111100100001010100011011000111000000010011001110101101111010111110010001001001000000011000010110001101111100001111000000001011111100000100110001011010111010101000101100110001111010011001000001111000000011110000010010001110000001110001100001011000011111000111101111000100111100010011010110110001101110111101001100001101100010100000010011100000110000111011001100100100001000011101000011011111011110010100100100010000001110110101111001100100000010011100010010010001101010110111111111001011100001100111110111011010000001001010100111111001010011010101011001010011011110111001110011111100111010000010001001000100101000010000110000011010000100001100101110111000011100011100111111010011100100010001100011001100011111111110000110100110000010001011111001111011100111010100000111100101001010100100111100000100100000101001111111110110100011110000100101100100011110000100100001001001011111011111000111001001101011110000111000000110000100110100001101000100011010110001010011010110111111001111110001011000011111100000011011010000011110101011101100000001100010010011111001101100011101000010010101111110111100000011000111000110011110101101011100110111101011111010000111011100101010110010000110001001011101011111011111011010000000001011101011000100110111000111111001110100111110110001100100011000011001001011111000100101101101001100010100010001110010110010011110111000010110011110110110011110110111000101101101100000101110111110000001110011010110011010111001101010001101111011011001110101010000000110010101010010010110010100110100001011001000110110110110111011111001101010011011110011001111011001101000111101101110101111100011010011101010110101000110010001000111100111000111110100100100011110010111111110110110101000111000001011110010110001100011011011101010100011001100101101010100111000000001100111110011010101101000101101110111011000101011111100001010111110100000101001001110011010010100110000100010000100011100110000010001110010010010101100001011110101010000010001011011001100000101100100010110101000101010110011101001011001110011000010101101010000001101110111110010000111001001110110000010001111110110101000010001000111100110101110011111011100000110000010000001000001000001010000110110010101000101110000101110000011101010100110111101101100110101000010000100110100011010101010001110110010100111011011011111110101001110101000111100101110110010110111100110101000101111010001000110111000111100010110000011001110010100001010011000110101101100000110101010111100010011011010000110010001010000100111100111111011110001110100101011011001100001011010011101010001100101100101001110110111110011010111010010001100011000111001100010010001111000110101111111111100100100011101110101011001010010000001111111000101011111001010011111111011101001101100100011011000100001100101010000000010110001010111000111101101110001110010001111001111110000110100111100001001100111011110000111001000111010111011001111111011010110011011010100111010001101111000111111110000111101101110101101011111111011011100011010100010001100100110000011100000100100000110000110000001011001011101110010000100110110101001001001111011101101010111111011110011001100101010011110001000111111000100110001111100111001000100001100010111011111101000110001001111111110111111111110010111001001010101000100110000010001000010000111101110011010111101111000010010111111100101010000111011010100011101001001000101100111111000100011001001110000110100111111101100111100001110000010011010011100000111001001101001100100010100011111101110001011010100100111100010100111111011001111000101000011010111011000010001000101110001110101011101100011010010001010101001001110110010000000011000010010000000000010000111010001101001010100010110010110100001101101101101011111111011011001001111101100100010011011101111111110001010101100111010001100000100111010100110001110001101100101110110001001001111001111010001011101100010001111111001000110010010100001100001000100111000011111111110110001111100000101110000111010000100111000100101000000110010000001111010101001010101000001111011010010011001110110111010010101110101100110010100011000100011100011001111110101001011111100100010000000110000101001101101011111100111100101011111111100000011111111010000001101100011011110101101100001110001110010110000100111010010100011110101001100001101011110110011000001100101100111110101111011001000001110111100010000101011100101110001111110010100110001000110011101010110111001000011010100010011111011110011000110111111101001100000101101111100100100000010001110011010100101010111011001111000101101000000100011110001100011000000011000110110110011001001100101000001011010110110111101001010100100010010110100111101101001001000110011100101110100100110011000110110110100101001001001101100110110011100100011110010011010001100001100101111000111111111010111011110110100111001101010100110101100001000110011010000111000000001110101111001111100100010010010100111011000101000000010100111110110000110001101100011011111111111100110000001001101100001110010101000100100100011111010101001001101000011010101100100101000110111110111101101100010000101110100001111110000010110111011111010000010001011011000011111010001001000100010001110111100111000001101111111111101101011011001001111101101111101100000010101010100101011110011101111101000100111000111000010111101100000111100000100110011011011111110100001100001011110100110000001101111001111010010001100001110001000010000100001110111011101111111101111111101110110110011101010100010000000010111011110010111010110110010110010101000000010000011000010000101001100000000010110000010000010110010010100100100111000011001100010110101000101100101110011000011010100001100010011100011111100101100010101010101001100101101110101101110110100001100110001111010000011011010100011100100011001111001010010111000110101001100110101000001010101000110011000010001100010100011101111101010011011011010010011101010000101001000010010100011110001000010111111000010101101110110111011101111001000100011101000100001100001110101000011101101001100001100011000000010000000001110000111000000010111100101010100110010010101000000011010011001111110100111100101010101111100101110000101011011011111100100101100001010110001110100001111010100000110011000111110101001100000111101011101111101010010010001111010001111101001110000001111101111010011011011111101101011101110101010111011011001110100010010111101111101001000011001001110000111110100100000000001110000001010011000110010100011000100100100101111111000100111110010000111010110110001000111111110001110011111011100010011011110011110011111110111001111101101101010101011101110111000111101010000101011000010000000111110001000001100100101110000011010010111100001101010100101100100010010100101000101001010101000001000011100100001001111101110111010111000011101011011100000100011010110110111100101001111110011100111010101111100000110010010101010111001111010110010001001010010110101010001110011001111001011001100110010010001110110100111001100110011000110101010000000110110000101111010011001111110010101000111010010011001110110110010010010000101101101100111000110001101100011011100101010010101010011011110101010100111111001010111010111101001111101001111001111110011011001111001110101000001011111010111000111101011001011101101000011000111110111110001000111011010001000110010011110001101110110101010100010110011111001010110001010010000110000110000110011111101011100101011100111101010000111011101111101011000001100001001010111110110001101111111100101101001011111010101011010111100101001011100111101100010100110000101000011000000011100010110110101000111101111001110000010010101111011001101011110100011011111110010100000111111011001101010111011101011000001001010011010001011100100111001110000000100100110001011000101100110111001010111111011101000010101011111001001111101101111011011101101011000000100110010000010111111101101101101000011000111100011000100011000011000000011111100000110101011101111001010010110010011001111011110000000001111100011110000110011100001000101011101110111110000110011100011101111100000011101100111111011000000101100011101110111101111011011101010111011001110110110011010110101111110101010100010111100110010010000000110010100101011111110101001011111011010110010001000001010011111011010110111101101101111011000100011011000100010110001011110110010011001111000110001110011010001010111000011011010111011110000011100011110110010100101001101111101110101110010111101001110110101110110011001000000110110000000001000011111010101110101111111011101101101100010000000100111000100000110110011010000010101101001111010100000101100000100100011010111101100011110111011011000010100100110100110101001010011110110011101010110000000101001010000110110111000110100100000000011000110101100000000001110010110000001010100100001110101100100111101100100110111100110100111111111000011010010011010000001111100010110100001011100010000010100110011101111000011011100001011010010010110001011000001110100001110100101101011010000101011110111001111001101001001001111100101000110011101001111110101111100110101110100101111101000111110010011001100110001001110100011100000001010000110110010011101110111001001001011101100110000111110000010110010001000100111111001100010100000011110011011110111000000000101111011110111010101110010011011011100001100001001101100011000010110011000101100001110001111100000010111100001110101100110100001100000011100110101001110110100100011110111111001001100100111010111010110110000001111010110001111101111100100010110001011001111000001101011011111101111000010010010111011100110111100100110010110111000001010100000001101010110001010001001010011010000111110010111100000110010000110110000100011101110000101111110001101001001000010011111100001011101011001010100001000110000101001100001010101100101001011000111010101000001111000111100000100001111100011000000111000101010100111111110101010011010101011000111101101010011001010101010000111011110010111001101001101010100100110001100010001111110100110001100010100110101111100011101001100001101111111110110010010110100001101001111001100101010100011010100111111101100101100000010100110111011000001001000000001110100001110111011011010000100101011011100100011100111001101101101011110001011011000111001000001000101111111100111100000111011000100111100101111010011110000110100110011101010000110110101101000011011011010110011110101110110000011110101110001110001001111101111100010110100001010101000101000101001101110011001101111000100000000010100110100110011001010001100110100011100100101010001010001010101001101010101001001100010001011000111011101001110110101111111010101000001011101011011011101101011001000101011110110010001100011111111101100101111110111011001010001001000001100111010111111110001110110110100010000010011001101001111000010001010011000011011000101101000011111101100111101010110000100101101001111000000111100010110110001001001001011111111100000010110100100110010010010101101110111101000001010111100010100011011101001100000001100110001110111101011011101011110001110101011110001011100100101011010100000101010000100100110101011001011100111110011011011100100000111011101111111001010100100111111001001000101100001001011000011110000010100110000110010111011110111010111011100100011101000100111101110000010000110011111110101010111100000101001101111100010110101000100111110000010011000100000000101010001111010100011101101000111101100001110010101100100011101011011100110011001000011110111010100101011100110100101000110001100100110001101001000101011001110011010011111110001001010101100101100000010111110001010001010100110001000101111110011101010100001011100010010011001101000101011011111101111010110010111100010011110001100001110110000000111101011000001100010100010110011010100011110000110110100001010000110111010011000100100011101000000000101110101111010110000010010111101100011101000110111010111010000101001100110011011010111111001011010011110000101001101001111000000011111001001110010010111101001010010001001000011100100101010010010001101111111011001000011010101100010111001001010001000001010010011101101111011110111010101110001100001000101001100110001010000011011001100001110101010100001100000110011100111101000000101100010101001010101010100010000000101110111001000100010110001110101010000001111100101101001011011101100110000000010001100111010111000000100110110000001010011001011100011101000001000010011110100111100010100001000000010011000010000001101010010100111110011011101110011010001111110001000001011110110001111101001011111100001101101100011111011111010110011000000101010100000111101001001010111010000100000100001100010111011110011110000110011010001100001110100101110100000010000011001110110111100001001100000000010011010011010001100110100110110001100101001000000101010011111010100011010101001101100001110110011000010011010011100100011000100011000000000100000000100110001010101111011100110010100111101111011010010000101001011110011110110000010111010011111011110001000001110100110001011110111101111110000001001110101100110010101011111101000011011000110011011010010011000011101010100011101001000111100001000011100011000101100001001001011101111011100010001101100010110001101110111111100001111011010011001111101111011010000101110101011110011110011101000101000100100001101101000100000001011110010000001111111011010011111111111011100101110000001100000011011011101101100010011110100011100101111011111101010101010000011011100011101111011000010011000001111011010101011111001010001110000100101110110000111001011000010100001010000110110111001010110010000100101101110010110010101011000010100010101111010110111001011011101100001010010000111100101111100111011110000101010000101101000011111110010011011100101101100000011011100110111000010110100000000010111011111111110100010000110010111110010011010111000001010111110101001100100001100000100001100101001010010110101000000011111110011011111111100111100011010101111110100100010010000101110100010010101010101011000101001100110101001011011001011110001000101101000111101111110010110101001001001000000001000001110101000111101100111010101110000001001111101110100001000011001011100111010011001001010011100110001111101100111100000001001000100101011011101011100100110111101011100111101001100010001111011101010100101101101100111101101010100011011111010101000111110011011111010001100000000010000100001000010010011100100111100101001110111101100110100011010101110010001011010111001001011000001100010000011000001100010000100000101110000000100100101000000100010011000110100001111011011111111000010011000110100100000100001000001110011101101100100101110101101110101111110101101111111101010011011110001011111010100001010110010101101100111001110010000111011101011100010101100110000100101000110111101101001011001001101001001011010110101011001000011111011000011001110101010000111111101100110001100101100111011111111110001111011001101111111111100111001100101011011011100000101111010001011101011100101000101110011100110100111001000000000110100101001010111010000101000010000110001111110011101110100100111101010101010101011000000001110000100010101001000011100101011111000101111100100100110100100011111111010110010101111111101000100010100110101001001110111011111000111000000101000111011011000111000000001101111100011001010000010111100001111100101100010110000110100110011000101101010101111101110001000001101010100000010000100010001100111100111010001010110101111011110001001101111101010101011101100101001011000110110110101010000001011000011001101100001010000101010110101111000011111000011101101000001111101100100001001110001111101101010000110100010100010110101101000010111010111100010111010011110000000000010000100000100001010111011000010000110101000001101010001111110110101110010101000001011000100000110010000100110001110100001011100111010111101110101101000101000000011000011101011010100100000000011100000001010110000000000000011101011110111110101001010011000110010011101011101000100000111110010001001110110100101011101001010111101100011110001011010100000101000101001100111000110111111110100101111111100000111100100100101000100010000011001000101010010110101011011110110000001010110010100101101001011010011111100101110000111101001100101001000110000000100101101110011000001000010011100010001011110110001011111010011001000101110110100000011110100111000110110101101000010011000011111010101011100011101001010010000010011001011011000110011001000100001010000000111111011100101101111011011110100100010010100001101011110010010110111100011110010011100111010011010111010000100010111101010010011000110111101100101010000000110011110100110010111111111110101001001110110100110010111010110110010010001110000110010011000011001111011111100111001110001110001110110111011100110110111001000110011000100100010100000101111010110110001001111000110000100010111101100100011110111000101001110111101000101101001110111111100001000111000010110110001100010101110001010011001100101001001110011111100010001000101111111100101101000100100101010111001110100111111000000101111011111011101100001111000111111110001101111101011011100101111011011100010110011111111110010100100000000000110110101110010100011111111101111001010110011111110111000101010011111001111011100001001011011011010111100110000110111000010101110100111101110010101000011101101010110101101110100111011001101010010110111101101101110110101101100001101001111011000000100000100010100001001001011011010101100000111101111100111000000111001111011011000010101110101010010011010101010011111111101010011101101001111101000010001111100001101110010001001010100000101000110111110001000011010011001101111100011011000110110000100101101111011000111100111110010001000100101101010001011010001011111011001101001001000000010100010011000000111000011110000110010001101110101100111001111101010000001000110001000101100110111100100011010010101011111001000110111011010000011011111101101101100101100111010001110010000110111111000101010011111110011001011001101001110011101001010111010010011000010100111101110000101101011000000111101111010101011000011000011101111100001110111000001100011000111111111111101111111101110010000001010001000010111000101011001111000011101110100010110010100101000011100001100100111010010111001101000000110000101110101001100101000110000110010001000110100101010011110001111110100111111101000101000001010000000011001111011110011011100000101011011001101010000011101111100111000000011011011010010100111001110111101011110011100001000111010100000000100011110011001010000000110110011011111001010100011000001011010100010111011001010000000010000001111011000001000011010001111011011010101011111001110111100010100100000001101111111011111000010110110101001101010001010111110000101011101110101101101001111010011011001111111001101101111111100101111011101011111000011101001110000010011111001001100001010100101101100000011111100100000010011000001010101010001110111101110001001010100110101010110001110111111011111001100011000011000110010100111111011111101011111011101111001000010111100011111001110100110100110000101000111101111110101101111111001100001001010110111100100100101000100001000010100110111101101111001001011111100110010000010001000101001001011101110010010100111100101101110010010000011001110110001101001010001010110011000111001100001011011110110101110000001001000111100111001001101001010001000011100001100010001000110101010101101100001101001110001110100100000001000100101100100001000001001111100101001001101111011110001100100111001111110001100000100110111110001010110110001000011110110111000100110110000011010111111011101111101100010110100111000011000100010101011011001000001111010110000000101111101110001010111010100110001011001110111111011100010011100111011100111110011010100001101001100100001101110110001100110111000000101100000111010111010100010000011000101011100000111111111101100000111111011110000010100110000110111111111011010110110010000111001001111000100000001110001100000001000001100000001100100111101001011001000111010010111101000110000000111111100011011110100001101001000111010101101001000000101111111000001011101010111100010110101011010101010001010001001111111000010011011111000101111110011000001010111001011001101110011100111110010010110101010111010111001010101111000111101001110011000001000101101111000110011110011011101110011000011101010101001100110001101001010101011101010100101100100110010110111100110010101101111110000101010011101110000100110010101111111000110110001110010011100110101010111010010100101011100011000011100101011001101100001100111110101000111010100000101100101010001011110101100011100111000011100001101011101101101110111011111100111100011110101101110010111001000000111100000111101011111110100001100111011110100011111100010111001101100000100100010000000001100111111001001010001010010100111111001101111011011100001110100110010110101001001110101001000100101101011000110001110010011010011101010100110111111111110001100111100010000011001010001000101100001001001011111000011101101101001111100101100000001101110101101010010110001111011101101101101101100000101100001000000111110111010100100000001100110110110001011100111000001000011001001000100000010011010011110001011010100010110110011100011001111100100001001011101010010001000100000101011100010011101110110100110110101000110110001011010110101100101010000001010111010000101011110110100000101111101111011101001011000010111010101011010011011000000100100010010001111110110110111100110000101111111001010110011001001000110000011010010000110000000110011100101110011101111100110011010101100101101111001010101011101011111000101110111110010110110010010110100101110100000011000011111001010010111101101110010100111011101001110001001000110101111001010101011110001010101111001111101001010111110010000001101100000100001001111101011101010001000000000001011000101011001010111111010011111011000010010100001000100010001011111011001010011000111000011011001011111011010111000111111100111001001100001100000100000101010101001000111010001001110100101100101011000001100100001011111111000011011111111111001010111101111001101010011111011110011000100001111101111011001110001001100000011011000011101111000100001010101001011011101010010100110111100001111101001000001000110001010000000101001010011010000111111101010100101011100001111011100010000011011101001000101011100010101000110100100101111111010110001011110010110010001010011110110011101100011111101100001001001101001101100001001101011000000000101110010011111011000100001011000001010100001000100101001010100000001010000010111011110011011000001010110001011011010111101110101010100110100100101101111100010101010110000000010110010111011001010001000011110110000100000011111111110000111001010100000000000010100110011001010000010000101111101001011011100111100001111101100101100100000010110010110011111110111010110101111101111100010111100100010111110100100001000001110011110000111111110110000100011010100001111000110001000100010010000001100100100011010101100001010010101100101111100101010001101100111011110011011010111011100000110010101100101111110100100000000100000100000111000010001111001100100000000000010101001000101000010100010100101111110000111111110100010010100011101100011100100011111001110111100100000110011011101000001011000100001111110100101100000111011110000101010010000110010110100010110000010011101101000001101101110010000110100100111011111110001000011101011000101111011000100011001100000001111110100111011000001111111101011000011100110011000111011010110010110110111010010000101100110111011100000101110011000000110101000110111110011100110100011110100001011101001001101110110010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
259
260            ;; testing base converters on small ints
261            ;; octal
262            (("%o" 126) . "176")
263            (("%+o" 126) . "+176")
264            (("% o" 126) . " 176")
265            (("% +o" 126) . "+176")
266            (("%+ o" 126) . "+176")
267            (("%#o" 126) . "0o176")
268            (("%#+o" 126) . "+0o176")
269            (("%# o" 126) . " 0o176")
270            (("%# +o" 126) . "+0o176")
271            (("%#+ o" 126) . "+0o176")
272            (("%6o" 126) . "   176")
273            (("%+6o" 126) . "  +176")
274            (("% 6o" 126) . "   176")
275            (("% +6o" 126) . "  +176")
276            (("%+ 6o" 126) . "  +176")
277            (("%-6o" 126) . "176   ")
278            (("%+-6o" 126) . "+176  ")
279            (("% -6o" 126) . " 176  ")
280            (("% +-6o" 126) . "+176  ")
281            (("%+ -6o" 126) . "+176  ")
282            (("%#8o" 126) . "   0o176")
283            (("%#+8o" 126) . "  +0o176")
284            (("%# 8o" 126) . "   0o176")
285            (("%# +8o" 126) . "  +0o176")
286            (("%#+ 8o" 126) . "  +0o176")
287            (("%#-8o" 126) . "0o176   ")
288            (("%#+-8o" 126) . "+0o176  ")
289            (("%# -8o" 126) . " 0o176  ")
290            (("%# +-8o" 126) . "+0o176  ")
291            (("%#+ -8o" 126) . "+0o176  ")
292            (("%o" -126) . "-176")
293            (("%+o" -126) . "-176")
294            (("% o" -126) . "-176")
295            (("% +o" -126) . "-176")
296            (("%+ o" -126) . "-176")
297            (("%#o" -126) . "-0o176")
298            (("%#+o" -126) . "-0o176")
299            (("%# o" -126) . "-0o176")
300            (("%# +o" -126) . "-0o176")
301            (("%#+ o" -126) . "-0o176")
302            (("%6o" -126) . "  -176")
303            (("%+6o" -126) . "  -176")
304            (("% 6o" -126) . "  -176")
305            (("% +6o" -126) . "  -176")
306            (("%+ 6o" -126) . "  -176")
307            (("%-6o" -126) . "-176  ")
308            (("%+-6o" -126) . "-176  ")
309            (("% -6o" -126) . "-176  ")
310            (("% +-6o" -126) . "-176  ")
311            (("%+ -6o" -126) . "-176  ")
312            (("%#8o" -126) . "  -0o176")
313            (("%#+8o" -126) . "  -0o176")
314            (("%# 8o" -126) . "  -0o176")
315            (("%# +8o" -126) . "  -0o176")
316            (("%#+ 8o" -126) . "  -0o176")
317            (("%#-8o" -126) . "-0o176  ")
318            (("%#+-8o" -126) . "-0o176  ")
319            (("%# -8o" -126) . "-0o176  ")
320            (("%# +-8o" -126) . "-0o176  ")
321            (("%#+ -8o" -126) . "-0o176  ")
322            ;; hexadecimal
323            (("%x" 126) . "7e")
324            (("%+x" 126) . "+7e")
325            (("% x" 126) . " 7e")
326            (("% +x" 126) . "+7e")
327            (("%+ x" 126) . "+7e")
328            (("%#x" 126) . "0x7e")
329            (("%#+x" 126) . "+0x7e")
330            (("%# x" 126) . " 0x7e")
331            (("%# +x" 126) . "+0x7e")
332            (("%#+ x" 126) . "+0x7e")
333            (("%6x" 126) . "    7e")
334            (("%+6x" 126) . "   +7e")
335            (("% 6x" 126) . "    7e")
336            (("% +6x" 126) . "   +7e")
337            (("%+ 6x" 126) . "   +7e")
338            (("%-6x" 126) . "7e    ")
339            (("%+-6x" 126) . "+7e   ")
340            (("% -6x" 126) . " 7e   ")
341            (("% +-6x" 126) . "+7e   ")
342            (("%+ -6x" 126) . "+7e   ")
343            (("%#8x" 126) . "    0x7e")
344            (("%#+8x" 126) . "   +0x7e")
345            (("%# 8x" 126) . "    0x7e")
346            (("%# +8x" 126) . "   +0x7e")
347            (("%#+ 8x" 126) . "   +0x7e")
348            (("%#-8x" 126) . "0x7e    ")
349            (("%#+-8x" 126) . "+0x7e   ")
350            (("%# -8x" 126) . " 0x7e   ")
351            (("%# +-8x" 126) . "+0x7e   ")
352            (("%#+ -8x" 126) . "+0x7e   ")
353            (("%x" -126) . "-7e")
354            (("%+x" -126) . "-7e")
355            (("% x" -126) . "-7e")
356            (("% +x" -126) . "-7e")
357            (("%+ x" -126) . "-7e")
358            (("%#x" -126) . "-0x7e")
359            (("%#+x" -126) . "-0x7e")
360            (("%# x" -126) . "-0x7e")
361            (("%# +x" -126) . "-0x7e")
362            (("%#+ x" -126) . "-0x7e")
363            (("%6x" -126) . "   -7e")
364            (("%+6x" -126) . "   -7e")
365            (("% 6x" -126) . "   -7e")
366            (("% +6x" -126) . "   -7e")
367            (("%+ 6x" -126) . "   -7e")
368            (("%-6x" -126) . "-7e   ")
369            (("%+-6x" -126) . "-7e   ")
370            (("% -6x" -126) . "-7e   ")
371            (("% +-6x" -126) . "-7e   ")
372            (("%+ -6x" -126) . "-7e   ")
373            (("%#8x" -126) . "   -0x7e")
374            (("%#+8x" -126) . "   -0x7e")
375            (("%# 8x" -126) . "   -0x7e")
376            (("%# +8x" -126) . "   -0x7e")
377            (("%#+ 8x" -126) . "   -0x7e")
378            (("%#-8x" -126) . "-0x7e   ")
379            (("%#+-8x" -126) . "-0x7e   ")
380            (("%# -8x" -126) . "-0x7e   ")
381            (("%# +-8x" -126) . "-0x7e   ")
382            (("%#+ -8x" -126) . "-0x7e   ")
383            )))
384
385     (mapc #'(lambda (f)
386               (let ((format (cons 'format (car f)))
387                     (expected (cdr f)))
388                 (eval `(Assert (string= ,format ,expected)))))
389           forms)))
390
391
392 ;; now testing bigq formatting
393 (when (featurep 'bigq)
394   (let ((forms
395          '((("%Q" 2) . "2")
396            (("%2Q" 2) . " 2")
397            (("%2Q" 200) . "200")
398            (("%+Q" 2) . "+2")
399            (("% Q" 2) . " 2")
400            (("% +Q" 2) . "+2")
401            (("%+ Q" 2) . "+2")
402            (("%Q" -2) . "-2")
403            (("% Q" -2) . "-2")
404            (("%+Q" -2) . "-2")
405            (("% +Q" -2) . "-2")
406            (("%+ Q" -2) . "-2")
407            (("%-4Q" 2) . "2   ")
408            (("%.2Q" 2) . "2")
409            (("%4.2Q" 2) . "   2")
410            (("%-4.2Q" 2) . "2   ")
411
412            ;; testing with proper fractions
413            (("%Q" 2/3) . "2/3")
414            (("%5Q" 2/3) . "  2/3")
415            (("%5.5Q" 2/3) . "  2/3")
416            (("%+Q" 2/3) . "+2/3")
417            (("% Q" 2/3) . " 2/3")
418            (("% +Q" 2/3) . "+2/3")
419            (("%+ Q" 2/3) . "+2/3")
420            (("%Q" (float 1.5)) . "3/2")
421            (("%Q" (float 0.66666)) . "3002369727582815/4503599627370496")
422            (("%-10Q" 2/3) . "2/3       ")
423
424            ;; testing coercion to Z
425            (("%d" 4/3) . "1")
426            (("%Z" 2/3) . "0"))))
427
428     (mapc #'(lambda (f)
429               (let ((format (cons 'format (car f)))
430                     (expected (cdr f)))
431                 (eval `(Assert (string= ,format ,expected)))))
432           forms)))
433
434
435 (when (featurep 'bigfr)
436   (let ((forms
437          '((("%f" (exp 1)) . "2.718282")
438            (("%2.2f" (exp 1)) . "2.72")
439            ;; this test uses a wrong output string deliberately
440            ;; it's wrong because the precision of IEEE-754 doubles is
441            ;; not enough to have 20 correct digits in the fractional part
442            ;; however, since we _can_ have long doubles now, this test
443            ;; is no longer feasible since lisp should know a shit about
444            ;; the internal representation of fpfloats. -hroptatyr
445            ;;(("%2.20f" (exp 1)) . "2.71828182845904509080")
446
447            ;; now testing with %F
448            (("%F" (exp 1)) . "2.718281828459045235360287471352662497759")
449            (("%2.2F" (exp 1)) . "2.71")
450            (("%+2.2F" (exp 1)) . "+2.71")
451            (("%10.0F" (exp 1)) . "         2")
452            (("%10.1F" (exp 1)) . "       2.7")
453            (("%12.12F" (exp 1)) . "2.718281828459")
454            (("%30.12F" (exp 1)) . "                2.718281828459")
455            (("%5.5F" (exp 13)) . "442413.39200")
456            (("%F" (/ (exp 1))) .
457             "0.3678794411714423215955237701614608674462")
458            (("%2.2F" (/ (exp 1))) . "0.36")
459            (("%3.3F" (/ (exp 1))) . "0.367")
460            (("%.5F" (bigfr 1)) . "1.00000")
461
462            (("%.4F" (bigfr 23213231 25)) . "23213231.0000")
463            ;; stupid assumption
464            ;;(("%.4F" (bigfr 23213231 8)) . "23200000.0000")
465            (("%Z" (bigfr 23213231 25)) . "23213231")
466            (("%Z" (bigfr 23213231 8)) . "23199744")
467
468            (("%+.4f" 2) . "+2.0000")
469            (("%+.4F" 2) . "+2.0000")
470            (("% .4F" 2) . " 2.0000")
471            (("%+10.4F" 2) . "   +2.0000")))
472         (default-real-precision 128))
473
474     (mapc #'(lambda (f)
475               (let ((format (cons 'format (car f)))
476                     (expected (cdr f)))
477                 (eval `(Assert (string= ,format ,expected)))))
478           forms)))
479
480 (when (featurep 'bigg)
481   (let ((forms
482          '((("%B" 2+i) . "2+1i")
483            (("%+B" 2+i) . "+2+1i")
484            (("% B" 2+i) . " 2+1i")
485            (("%B" 2+i) .
486             (format "%Z%+Zi" (real-part 2+i) (imaginary-part 2+i)))
487            (("%B" 1) . "1+0i")
488            (("%+10.4B" 1.2) . "     +0001     +0000i")
489            (("%-10.4B" 0+2i) . "0000      +0002     i"))))
490
491     (mapc #'(lambda (f)
492               (let ((format (cons 'format (car f)))
493                     (expected (cdr f)))
494                 (eval `(Assert (string= ,format ,expected)))))
495           forms))
496
497   ;; Gaussian numbers shall not be coerced to comparables
498   (Check-Error domain-error (format "%d" 1+i))
499   (Check-Error domain-error (format "%f" 1+i))
500   (when (featurep 'bigq)
501     (Check-Error domain-error (format "%Q" 1+i)))
502   (when (featurep 'bigfr)
503     (Check-Error domain-error (format "%F" 1+i))))
504
505
506 (when (featurep 'bigc)
507   (let ((forms
508          '((("%.2C" 2+i) . "2.00+1.00i")
509            (("%+.2C" 2+i) . "+2.00+1.00i")
510            (("% .2C" 2+i) . " 2.00+1.00i")
511            (("%.2C" 2+i) .
512             (format "%.2F%+.2Fi" (real-part 2+i) (imaginary-part 2+i)))
513            (("%.2C" 1) . "1.00+0.00i")
514            (("%+10.4C" 1.5) . "   +1.5000   +0.0000i")
515            (("%-10.4C" 0+2i) . "0.0000    +2.0000   i"))))
516
517     (mapc #'(lambda (f)
518               (let ((format (cons 'format (car f)))
519                     (expected (cdr f)))
520                 (eval `(Assert (string= ,format ,expected)))))
521           forms))
522
523   ;; complex numbers shall not be coerced to comparables
524   (Check-Error domain-error (format "%d" (sqrt -2)))
525   (Check-Error domain-error (format "%f" (sqrt -2)))
526   (when (featurep 'bigq)
527     (Check-Error domain-error (format "%Q" (sqrt -2))))
528   (when (featurep 'bigfr)
529     (Check-Error domain-error (format "%F" (sqrt -2)))))
530
531 ;; the new %b thing
532 (let ((forms
533        '((("%b" 12) . "1100")
534          (("%8b" 12) . "    1100")
535          (("%08b" 12) . "00001100"))))
536   (mapc #'(lambda (f)
537             (let ((format (cons 'format (car f)))
538                   (expected (cdr f)))
539               (eval `(Assert (string= ,format ,expected)))))
540         forms))
541
542 ;; exterior precision
543 (Assert (equal (format "%*d" 10 4) "         4"))
544 (Assert (equal (format "%#!_*x" 10 4) "_______0x4"))
545
546 ;; lisp reader syntax
547 (Assert (equal (format "%#~x" 19) "0x13"))
548 (Assert (equal (format "%#~x" -19) "0x-13"))
549 (Assert (equal (format "%&x" 19) "#x13"))
550 (Assert (equal (format "%&~x" 19) "#x13"))
551 (Assert (equal (format "%&x" -19) "#x-13"))
552 (Assert (equal (format "%&~x" -19) "#x-13"))
553 ;; check spacing
554 (Assert (equal (format "%&+x" 19) "#x+13"))
555 (Assert (equal (format "%&~+x" 19) "#x+13"))
556 (Assert (equal (format "%&+x" -19) "#x-13"))
557 (Assert (equal (format "%&~+x" -19) "#x-13"))
558 (Assert (equal (format "%& x" 19) "#x13"))
559 (Assert (equal (format "%&~ x" 19) "#x13"))
560 (Assert (equal (format "%& x" -19) "#x-13"))
561 (Assert (equal (format "%&~ x" -19) "#x-13"))
562
563 (Assert (equal (format "%&0*x" 10 4) "#x00000004"))
564 (Assert (equal (format "%&0.*x" 10 4) "#x0000000004"))
565
566 ;;; format-tests.el ends here