![]() |
|
Главная Терминология Хоора 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 [ 20 ] 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 begin message ( digit expected); halt; :. end ; a:=0, e := 0; repeat if a < limit then a := 10*a + ord(ch)-rZ else e ej get(f); ch := Л until -ich in [0.. 9]); if cA = . then begin [чтение дробной uaemu] getif); ch :=: ff; while ch in [0.. 9] do begin if a < limit then bin a := 10*й + ord{ch)-z; в := e-\ end ; ge/(/); cA := Л end end ; -ifThen---- begin [чтение порядка] gei(f); ch :=/t; i := 0; if ch = - then begin ss := true; get(f); ch := /j end else begin ss := false; if ch = + then beginge<(/); cA :=/t end end ; while ch in [0.. S] do begin if i<limit then begin i := 10*i + crd(ch)~Z end; ger(/);cA:=/t end ; if ss then e := c-i else e e+/ end ; if e < Urn. 2 then begin a := 0; e := 0 end else it e > lim 1 then begin messagei; number too large ); halt eni; { 0 < йг < 2**49 } if fl > t48 then := ((ff+l) div 2) * 2.0 else :== a; if s then J :== -y; if e < 0 then x := yiteni-e) else if e 0 then X :== y*ten(e) else л; :== ; wbHe ( Л = ) Л(-o/(/)) do getif); end {readreal] Программа 1-3. Чтение вещественного числа. yvritereal (УйГ f: text; x: red; n: integer); :uibвещественного чистxcn символами в десятичном виде \11аваЮ1Цей запятой] aedyio foHcmanmbi зависят от используемого представления щсственных чисел с плавающей запятой] /48 - 281474976710656; (= 2 ** 48; 48-размер мантиссы 2-27; iordiO)} posint r= О.. 323; [диапазон для десятичного порядка] var cA integer; function/ (е: posint): real; { Ш*е, 0<c<322 } var i: integer; t: real; begin i 0; / := 1.0; repeat if о<И(е) then case I of 0: ; := / * l.OEl; 1; /:=/-* I.0E2; 2: / := / * 1.0E4; irt.- 3: / := / * 1.0E8; 4: / := / * 1.0E16; 5: / := / * I.0E32; 6: /:==/* 1.0E64; 7: / := / * 1.0E128; 8: / / * 1.0E256 end ; e := e div 2; / := j+1 until e = 0; tm / end [ten]; begin [требуются no крайней мере 10 симводов11-{-9.9В+999 } if л: = О then begta repeat wr e(/, );n := и-1 until и :< 1; write(f, 0) end else begin if и < 10 then и := 3 else n := n-7; repeat write(f, ); n :~ n-l until и < 15; { 1 < и < 1.5, число печатаемых 1ифр] begin [проверка знака, определение порядка] if X < О then begin Wj/eC/, ); л; := -д; end else write (f, 0. e := expo (x); [e = entier(Jog2(abs(x)))] 4.e>0 then iegin e := e*77 div 256 +1; л; := x/ten(e); if X >; 1.0 then begin л; := x/10.0; e := e+1 end end else begin e := (e+l)*77 div 256; л; :== Геп(-е)*х; if л: < 0.1 then begin X := 10.0*x; e := 1 end end ; 40.1 л; < 1.0 }-- case и of [округление] 2: л; := X+0.5E-2; 3; X := X+0.5E-3; 4: л; := л:+0.5Е-4; 5: X := x+0.5E-5; 6: Х+0.5Е-6; 7: л: :== Х+0.5Е-7; 8: л: := Х+0.5Е-8; 9: л: := Х+0.5Е-9; 10: X := л:+0.5Е-10; 11: л: := Х+0.5Е-11; 12: X := л:+0.5Е-12; 13: X := л:+0.5Е-13; 14: X := Х+0.5Е-14; 15: X := л;+0.5Е-15 end ; if X > 1.0 then begin X := X * 0.1; e := e+l; end ; с := trunc(x,4); {= Ггшс(х*(2**#5))] ;= 10*c; d := с div t4S; writeif, chrid+z), .); for / := 2 to и do begin с := (c - (/*/48) * 10; с div 48; writeif, chrid+z)} end ; TvnVeC/; E); e := if e < 0 then |