gsmisc.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. /* Copyright (C) 1989, 2000 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: gsmisc.c,v 1.22 2004/12/08 21:35:13 stefan Exp $ */
  14. /* Miscellaneous utilities for Ghostscript library */
  15. /*
  16. * In order to capture the original definition of sqrt, which might be
  17. * either a procedure or a macro and might not have an ANSI-compliant
  18. * prototype (!), we need to do the following:
  19. */
  20. #include "std.h"
  21. #if defined(VMS) && defined(__GNUC__)
  22. /* DEC VAX/VMS C comes with a math.h file, but GNU VAX/VMS C does not. */
  23. # include "vmsmath.h"
  24. #else
  25. # include <math.h>
  26. #endif
  27. inline private double
  28. orig_sqrt(double x)
  29. {
  30. return sqrt(x);
  31. }
  32. /* Here is the real #include section. */
  33. #include "ctype_.h"
  34. #include "malloc_.h"
  35. #include "math_.h"
  36. #include "memory_.h"
  37. #include "string_.h"
  38. #include "gx.h"
  39. #include "gpcheck.h" /* for gs_return_check_interrupt */
  40. #include "gserror.h" /* for prototype */
  41. #include "gserrors.h"
  42. #include "gconfigv.h" /* for USE_ASM */
  43. #include "gxfarith.h"
  44. #include "gxfixed.h"
  45. /* ------ Redirected stdout and stderr ------ */
  46. #include <stdarg.h>
  47. #define PRINTF_BUF_LENGTH 1024
  48. int outprintf(const gs_memory_t *mem, const char *fmt, ...)
  49. {
  50. int count;
  51. char buf[PRINTF_BUF_LENGTH];
  52. va_list args;
  53. va_start(args, fmt);
  54. count = vsprintf(buf, fmt, args);
  55. outwrite(mem, buf, count);
  56. if (count >= PRINTF_BUF_LENGTH) {
  57. count = sprintf(buf,
  58. "PANIC: printf exceeded %d bytes. Stack has been corrupted.\n",
  59. PRINTF_BUF_LENGTH);
  60. outwrite(mem, buf, count);
  61. }
  62. va_end(args);
  63. return count;
  64. }
  65. int errprintf(const char *fmt, ...)
  66. {
  67. int count;
  68. char buf[PRINTF_BUF_LENGTH];
  69. va_list args;
  70. va_start(args, fmt);
  71. count = vsprintf(buf, fmt, args);
  72. errwrite(buf, count);
  73. if (count >= PRINTF_BUF_LENGTH) {
  74. count = sprintf(buf,
  75. "PANIC: printf exceeded %d bytes. Stack has been corrupted.\n",
  76. PRINTF_BUF_LENGTH);
  77. errwrite(buf, count);
  78. }
  79. va_end(args);
  80. return count;
  81. }
  82. /* ------ Debugging ------ */
  83. /* Ghostscript writes debugging output to gs_debug_out. */
  84. /* We define gs_debug and gs_debug_out even if DEBUG isn't defined, */
  85. /* so that we can compile individual modules with DEBUG set. */
  86. char gs_debug[128];
  87. FILE *gs_debug_out;
  88. /* Test whether a given debugging option is selected. */
  89. /* Upper-case letters automatically include their lower-case counterpart. */
  90. bool
  91. gs_debug_c(int c)
  92. {
  93. return
  94. (c >= 'a' && c <= 'z' ? gs_debug[c] | gs_debug[c ^ 32] : gs_debug[c]);
  95. }
  96. /* Define the formats for debugging printout. */
  97. const char *const dprintf_file_and_line_format = "%10s(%4d): ";
  98. const char *const dprintf_file_only_format = "%10s(unkn): ";
  99. /*
  100. * Define the trace printout procedures. We always include these, in case
  101. * other modules were compiled with DEBUG set. Note that they must use
  102. * out/errprintf, not fprintf nor fput[cs], because of the way that
  103. * stdout/stderr are implemented on DLL/shared library builds.
  104. */
  105. void
  106. dflush(void)
  107. {
  108. errflush();
  109. }
  110. private const char *
  111. dprintf_file_tail(const char *file)
  112. {
  113. const char *tail = file + strlen(file);
  114. while (tail > file &&
  115. (isalnum(tail[-1]) || tail[-1] == '.' || tail[-1] == '_')
  116. )
  117. --tail;
  118. return tail;
  119. }
  120. #if __LINE__ /* compiler provides it */
  121. void
  122. dprintf_file_and_line(const char *file, int line)
  123. {
  124. if (gs_debug['/'])
  125. dpf(dprintf_file_and_line_format,
  126. dprintf_file_tail(file), line);
  127. }
  128. #else
  129. void
  130. dprintf_file_only(const char *file)
  131. {
  132. if (gs_debug['/'])
  133. dpf(dprintf_file_only_format, dprintf_file_tail(file));
  134. }
  135. #endif
  136. void
  137. printf_program_ident(const gs_memory_t *mem, const char *program_name, long revision_number)
  138. {
  139. if (program_name)
  140. outprintf(mem, (revision_number ? "%s " : "%s"), program_name);
  141. if (revision_number) {
  142. int fpart = revision_number % 100;
  143. outprintf(mem, "%d.%02d", (int)(revision_number / 100), fpart);
  144. }
  145. }
  146. void
  147. eprintf_program_ident(const char *program_name,
  148. long revision_number)
  149. {
  150. if (program_name) {
  151. epf((revision_number ? "%s " : "%s"), program_name);
  152. if (revision_number) {
  153. int fpart = revision_number % 100;
  154. epf("%d.%02d", (int)(revision_number / 100), fpart);
  155. }
  156. epf(": ");
  157. }
  158. }
  159. #if __LINE__ /* compiler provides it */
  160. void
  161. lprintf_file_and_line(const char *file, int line)
  162. {
  163. epf("%s(%d): ", file, line);
  164. }
  165. #else
  166. void
  167. lprintf_file_only(FILE * f, const char *file)
  168. {
  169. epf("%s(?): ", file);
  170. }
  171. #endif
  172. /* Log an error return. We always include this, in case other */
  173. /* modules were compiled with DEBUG set. */
  174. #undef gs_log_error /* in case DEBUG isn't set */
  175. int
  176. gs_log_error(int err, const char *file, int line)
  177. {
  178. if (gs_log_errors) {
  179. if (file == NULL)
  180. dprintf1("Returning error %d.\n", err);
  181. else
  182. dprintf3("%s(%d): Returning error %d.\n",
  183. (const char *)file, line, err);
  184. }
  185. return err;
  186. }
  187. /* Check for interrupts before a return. */
  188. int
  189. gs_return_check_interrupt(const gs_memory_t *mem, int code)
  190. {
  191. if (code < 0)
  192. return code;
  193. {
  194. int icode = gp_check_interrupts(mem);
  195. return (icode == 0 ? code :
  196. gs_note_error((icode > 0 ? gs_error_interrupt : icode)));
  197. }
  198. }
  199. /* ------ Substitutes for missing C library functions ------ */
  200. #ifdef MEMORY__NEED_MEMMOVE /* see memory_.h */
  201. /* Copy bytes like memcpy, guaranteed to handle overlap correctly. */
  202. /* ANSI C defines the returned value as being the src argument, */
  203. /* but with the const restriction removed! */
  204. void *
  205. gs_memmove(void *dest, const void *src, size_t len)
  206. {
  207. if (!len)
  208. return (void *)src;
  209. #define bdest ((byte *)dest)
  210. #define bsrc ((const byte *)src)
  211. /* We use len-1 for comparisons because adding len */
  212. /* might produce an offset overflow on segmented systems. */
  213. if (PTR_LE(bdest, bsrc)) {
  214. register byte *end = bdest + (len - 1);
  215. if (PTR_LE(bsrc, end)) {
  216. /* Source overlaps destination from above. */
  217. register const byte *from = bsrc;
  218. register byte *to = bdest;
  219. for (;;) {
  220. *to = *from;
  221. if (to >= end) /* faster than = */
  222. return (void *)src;
  223. to++;
  224. from++;
  225. }
  226. }
  227. } else {
  228. register const byte *from = bsrc + (len - 1);
  229. if (PTR_LE(bdest, from)) {
  230. /* Source overlaps destination from below. */
  231. register const byte *end = bsrc;
  232. register byte *to = bdest + (len - 1);
  233. for (;;) {
  234. *to = *from;
  235. if (from <= end) /* faster than = */
  236. return (void *)src;
  237. to--;
  238. from--;
  239. }
  240. }
  241. }
  242. #undef bdest
  243. #undef bsrc
  244. /* No overlap, it's safe to use memcpy. */
  245. memcpy(dest, src, len);
  246. return (void *)src;
  247. }
  248. #endif
  249. #ifdef MEMORY__NEED_MEMCPY /* see memory_.h */
  250. void *
  251. gs_memcpy(void *dest, const void *src, size_t len)
  252. {
  253. if (len > 0) {
  254. #define bdest ((byte *)dest)
  255. #define bsrc ((const byte *)src)
  256. /* We can optimize this much better later on. */
  257. register byte *end = bdest + (len - 1);
  258. register const byte *from = bsrc;
  259. register byte *to = bdest;
  260. for (;;) {
  261. *to = *from;
  262. if (to >= end) /* faster than = */
  263. break;
  264. to++;
  265. from++;
  266. }
  267. }
  268. #undef bdest
  269. #undef bsrc
  270. return (void *)src;
  271. }
  272. #endif
  273. #ifdef MEMORY__NEED_MEMCHR /* see memory_.h */
  274. /* ch should obviously be char rather than int, */
  275. /* but the ANSI standard declaration uses int. */
  276. void *
  277. gs_memchr(const void *ptr, int ch, size_t len)
  278. {
  279. if (len > 0) {
  280. register const char *p = ptr;
  281. register uint count = len;
  282. do {
  283. if (*p == (char)ch)
  284. return (void *)p;
  285. p++;
  286. } while (--count);
  287. }
  288. return 0;
  289. }
  290. #endif
  291. #ifdef MEMORY__NEED_MEMSET /* see memory_.h */
  292. /* ch should obviously be char rather than int, */
  293. /* but the ANSI standard declaration uses int. */
  294. void *
  295. gs_memset(void *dest, register int ch, size_t len)
  296. {
  297. /*
  298. * This procedure is used a lot to fill large regions of images,
  299. * so we take some trouble to optimize it.
  300. */
  301. register char *p = dest;
  302. register size_t count = len;
  303. ch &= 255;
  304. if (len >= sizeof(long) * 3) {
  305. long wd = (ch << 24) | (ch << 16) | (ch << 8) | ch;
  306. while (ALIGNMENT_MOD(p, sizeof(long)))
  307. *p++ = (char)ch, --count;
  308. for (; count >= sizeof(long) * 4;
  309. p += sizeof(long) * 4, count -= sizeof(long) * 4
  310. )
  311. ((long *)p)[3] = ((long *)p)[2] = ((long *)p)[1] =
  312. ((long *)p)[0] = wd;
  313. switch (count >> ARCH_LOG2_SIZEOF_LONG) {
  314. case 3:
  315. *((long *)p) = wd; p += sizeof(long);
  316. case 2:
  317. *((long *)p) = wd; p += sizeof(long);
  318. case 1:
  319. *((long *)p) = wd; p += sizeof(long);
  320. count &= sizeof(long) - 1;
  321. case 0:
  322. default: /* can't happen */
  323. DO_NOTHING;
  324. }
  325. }
  326. /* Do any leftover bytes. */
  327. for (; count > 0; --count)
  328. *p++ = (char)ch;
  329. return dest;
  330. }
  331. #endif
  332. #ifdef malloc__need_realloc /* see malloc_.h */
  333. /* Some systems have non-working implementations of realloc. */
  334. void *
  335. gs_realloc(void *old_ptr, size_t old_size, size_t new_size)
  336. {
  337. void *new_ptr;
  338. if (new_size) {
  339. new_ptr = malloc(new_size);
  340. if (new_ptr == NULL)
  341. return NULL;
  342. } else
  343. new_ptr = NULL;
  344. /* We have to pass in the old size, since we have no way to */
  345. /* determine it otherwise. */
  346. if (old_ptr != NULL) {
  347. if (new_ptr != NULL)
  348. memcpy(new_ptr, old_ptr, min(old_size, new_size));
  349. free(old_ptr);
  350. }
  351. return new_ptr;
  352. }
  353. #endif
  354. /* ------ Debugging support ------ */
  355. /* Dump a region of memory. */
  356. void
  357. debug_dump_bytes(const byte * from, const byte * to, const char *msg)
  358. {
  359. const byte *p = from;
  360. if (from < to && msg)
  361. dprintf1("%s:\n", msg);
  362. while (p != to) {
  363. const byte *q = min(p + 16, to);
  364. dprintf1("0x%lx:", (ulong) p);
  365. while (p != q)
  366. dprintf1(" %02x", *p++);
  367. dputc('\n');
  368. }
  369. }
  370. /* Dump a bitmap. */
  371. void
  372. debug_dump_bitmap(const byte * bits, uint raster, uint height, const char *msg)
  373. {
  374. uint y;
  375. const byte *data = bits;
  376. for (y = 0; y < height; ++y, data += raster)
  377. debug_dump_bytes(data, data + raster, (y == 0 ? msg : NULL));
  378. }
  379. /* Print a string. */
  380. void
  381. debug_print_string(const byte * chrs, uint len)
  382. {
  383. uint i;
  384. for (i = 0; i < len; i++)
  385. dputc(chrs[i]);
  386. dflush();
  387. }
  388. /* Print a string in hexdump format. */
  389. void
  390. debug_print_string_hex(const byte * chrs, uint len)
  391. {
  392. uint i;
  393. for (i = 0; i < len; i++)
  394. dprintf1("%02x", chrs[i]);
  395. dflush();
  396. }
  397. /*
  398. * The following code prints a hex stack backtrace on Linux/Intel systems.
  399. * It is here to be patched into places where we need to print such a trace
  400. * because of gdb's inability to put breakpoints in dynamically created
  401. * threads.
  402. *
  403. * first_arg is the first argument of the procedure into which this code
  404. * is patched.
  405. */
  406. #define BACKTRACE(first_arg)\
  407. BEGIN\
  408. ulong *fp_ = (ulong *)&first_arg - 2;\
  409. for (; fp_ && (fp_[1] & 0xff000000) == 0x08000000; fp_ = (ulong *)*fp_)\
  410. dprintf2(" fp=0x%lx ip=0x%lx\n", (ulong)fp_, fp_[1]);\
  411. END
  412. /* ------ Arithmetic ------ */
  413. /* Compute M modulo N. Requires N > 0; guarantees 0 <= imod(M,N) < N, */
  414. /* regardless of the whims of the % operator for negative operands. */
  415. int
  416. imod(int m, int n)
  417. {
  418. if (n <= 0)
  419. return 0; /* sanity check */
  420. if (m >= 0)
  421. return m % n;
  422. {
  423. int r = -m % n;
  424. return (r == 0 ? 0 : n - r);
  425. }
  426. }
  427. /* Compute the GCD of two integers. */
  428. int
  429. igcd(int x, int y)
  430. {
  431. int c = x, d = y;
  432. if (c < 0)
  433. c = -c;
  434. if (d < 0)
  435. d = -d;
  436. while (c != 0 && d != 0)
  437. if (c > d)
  438. c %= d;
  439. else
  440. d %= c;
  441. return d + c; /* at most one is non-zero */
  442. }
  443. /* Compute X such that A*X = B mod M. See gxarith.h for details. */
  444. int
  445. idivmod(int a, int b, int m)
  446. {
  447. /*
  448. * Use the approach indicated in Knuth vol. 2, section 4.5.2, Algorithm
  449. * X (p. 302) and exercise 15 (p. 315, solution p. 523).
  450. */
  451. int u1 = 0, u3 = m;
  452. int v1 = 1, v3 = a;
  453. /*
  454. * The following loop will terminate with a * u1 = gcd(a, m) mod m.
  455. * Then x = u1 * b / gcd(a, m) mod m. Since we require that
  456. * gcd(a, m) | gcd(a, b), it follows that gcd(a, m) | b, so the
  457. * division is exact.
  458. */
  459. while (v3) {
  460. int q = u3 / v3, t;
  461. t = u1 - v1 * q, u1 = v1, v1 = t;
  462. t = u3 - v3 * q, u3 = v3, v3 = t;
  463. }
  464. return imod(u1 * b / igcd(a, m), m);
  465. }
  466. /* Compute floor(log2(N)). Requires N > 0. */
  467. int
  468. ilog2(int n)
  469. {
  470. int m = n, l = 0;
  471. while (m >= 16)
  472. m >>= 4, l += 4;
  473. return
  474. (m <= 1 ? l :
  475. "\000\000\001\001\002\002\002\002\003\003\003\003\003\003\003\003"[m] + l);
  476. }
  477. #if defined(NEED_SET_FMUL2FIXED) && !USE_ASM
  478. /*
  479. * Floating multiply with fixed result, for avoiding floating point in
  480. * common coordinate transformations. Assumes IEEE representation,
  481. * 16-bit short, 32-bit long. Optimized for the case where the first
  482. * operand has no more than 16 mantissa bits, e.g., where it is a user space
  483. * coordinate (which are often integers).
  484. *
  485. * The assembly language version of this code is actually faster than
  486. * the FPU, if the code is compiled with FPU_TYPE=0 (which requires taking
  487. * a trap on every FPU operation). If there is no FPU, the assembly
  488. * language version of this code is over 10 times as fast as the emulated FPU.
  489. */
  490. int
  491. set_fmul2fixed_(fixed * pr, long /*float */ a, long /*float */ b)
  492. {
  493. ulong ma = (ushort)(a >> 8) | 0x8000;
  494. ulong mb = (ushort)(b >> 8) | 0x8000;
  495. int e = 260 + _fixed_shift - ( ((byte)(a >> 23)) + ((byte)(b >> 23)) );
  496. ulong p1 = ma * (b & 0xff);
  497. ulong p = ma * mb;
  498. #define p_bits (size_of(p) * 8)
  499. if ((byte) a) { /* >16 mantissa bits */
  500. ulong p2 = (a & 0xff) * mb;
  501. p += ((((uint) (byte) a * (uint) (byte) b) >> 8) + p1 + p2) >> 8;
  502. } else
  503. p += p1 >> 8;
  504. if ((uint) e < p_bits) /* e = -1 is possible */
  505. p >>= e;
  506. else if (e >= p_bits) { /* also detects a=0 or b=0 */
  507. *pr = fixed_0;
  508. return 0;
  509. } else if (e >= -(p_bits - 1) || p >= 1L << (p_bits - 1 + e))
  510. return_error(gs_error_limitcheck);
  511. else
  512. p <<= -e;
  513. *pr = ((a ^ b) < 0 ? -p : p);
  514. return 0;
  515. }
  516. int
  517. set_dfmul2fixed_(fixed * pr, ulong /*double lo */ xalo, long /*float */ b, long /*double hi */ xahi)
  518. {
  519. return set_fmul2fixed_(pr,
  520. (xahi & (3L << 30)) +
  521. ((xahi << 3) & 0x3ffffff8) +
  522. (xalo >> 29),
  523. b);
  524. }
  525. #endif /* NEED_SET_FMUL2FIXED */
  526. #if USE_FPU_FIXED
  527. /*
  528. * Convert from floating point to fixed point with scaling.
  529. * These are efficient algorithms for FPU-less machines.
  530. */
  531. #define mbits_float 23
  532. #define mbits_double 20
  533. int
  534. set_float2fixed_(fixed * pr, long /*float */ vf, int frac_bits)
  535. {
  536. fixed mantissa;
  537. int shift;
  538. if (!(vf & 0x7f800000)) {
  539. *pr = fixed_0;
  540. return 0;
  541. }
  542. mantissa = (fixed) ((vf & 0x7fffff) | 0x800000);
  543. shift = ((vf >> 23) & 255) - (127 + 23) + frac_bits;
  544. if (shift >= 0) {
  545. if (shift >= sizeof(fixed) * 8 - 24)
  546. return_error(gs_error_limitcheck);
  547. if (vf < 0)
  548. mantissa = -mantissa;
  549. *pr = (fixed) (mantissa << shift);
  550. } else
  551. *pr = (shift < -24 ? fixed_0 :
  552. vf < 0 ? -(fixed) (mantissa >> -shift) : /* truncate */
  553. (fixed) (mantissa >> -shift));
  554. return 0;
  555. }
  556. int
  557. set_double2fixed_(fixed * pr, ulong /*double lo */ lo,
  558. long /*double hi */ hi, int frac_bits)
  559. {
  560. fixed mantissa;
  561. int shift;
  562. if (!(hi & 0x7ff00000)) {
  563. *pr = fixed_0;
  564. return 0;
  565. }
  566. /* We only use 31 bits of mantissa even if sizeof(long) > 4. */
  567. mantissa = (fixed) (((hi & 0xfffff) << 10) | (lo >> 22) | 0x40000000);
  568. shift = ((hi >> 20) & 2047) - (1023 + 30) + frac_bits;
  569. if (shift > 0)
  570. return_error(gs_error_limitcheck);
  571. *pr = (shift < -30 ? fixed_0 :
  572. hi < 0 ? -(fixed) (mantissa >> -shift) : /* truncate */
  573. (fixed) (mantissa >> -shift));
  574. return 0;
  575. }
  576. /*
  577. * Given a fixed value x with fbits bits of fraction, set v to the mantissa
  578. * (left-justified in 32 bits) and f to the exponent word of the
  579. * corresponding floating-point value with mbits bits of mantissa in the
  580. * first word. (The exponent part of f is biased by -1, because we add the
  581. * top 1-bit of the mantissa to it.)
  582. */
  583. static const byte f2f_shifts[] =
  584. {4, 3, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0};
  585. #define f2f_declare(v, f)\
  586. ulong v;\
  587. long f
  588. #define f2f(x, v, f, mbits, fbits)\
  589. if ( x < 0 )\
  590. f = 0xc0000000 + (29 << mbits) - ((long)fbits << mbits), v = -x;\
  591. else\
  592. f = 0x40000000 + (29 << mbits) - ((long)fbits << mbits), v = x;\
  593. if ( v < 0x8000 )\
  594. v <<= 15, f -= 15 << mbits;\
  595. if ( v < 0x800000 )\
  596. v <<= 8, f -= 8 << mbits;\
  597. if ( v < 0x8000000 )\
  598. v <<= 4, f -= 4 << mbits;\
  599. { int shift = f2f_shifts[v >> 28];\
  600. v <<= shift, f -= shift << mbits;\
  601. }
  602. long
  603. fixed2float_(fixed x, int frac_bits)
  604. {
  605. f2f_declare(v, f);
  606. if (x == 0)
  607. return 0;
  608. f2f(x, v, f, mbits_float, frac_bits);
  609. return f + (((v >> 7) + 1) >> 1);
  610. }
  611. void
  612. set_fixed2double_(double *pd, fixed x, int frac_bits)
  613. {
  614. f2f_declare(v, f);
  615. if (x == 0) {
  616. ((long *)pd)[1 - arch_is_big_endian] = 0;
  617. ((ulong *) pd)[arch_is_big_endian] = 0;
  618. } else {
  619. f2f(x, v, f, mbits_double, frac_bits);
  620. ((long *)pd)[1 - arch_is_big_endian] = f + (v >> 11);
  621. ((ulong *) pd)[arch_is_big_endian] = v << 21;
  622. }
  623. }
  624. #endif /* USE_FPU_FIXED */
  625. /*
  626. * Compute A * B / C when 0 <= B < C and A * B exceeds (or might exceed)
  627. * the capacity of a long.
  628. * Note that this procedure takes the floor, rather than truncating
  629. * towards zero, if A < 0. This ensures that 0 <= R < C.
  630. */
  631. #define num_bits (sizeof(fixed) * 8)
  632. #define half_bits (num_bits / 2)
  633. #define half_mask ((1L << half_bits) - 1)
  634. /*
  635. * If doubles aren't wide enough, we lose too much precision by using double
  636. * arithmetic: we have to use the slower, accurate fixed-point algorithm.
  637. * See the simpler implementation below for more information.
  638. */
  639. #define MAX_OTHER_FACTOR_BITS\
  640. (ARCH_DOUBLE_MANTISSA_BITS - ARCH_SIZEOF_FIXED * 8)
  641. #define ROUND_BITS\
  642. (ARCH_SIZEOF_FIXED * 8 * 2 - ARCH_DOUBLE_MANTISSA_BITS)
  643. #if USE_FPU_FIXED || ROUND_BITS >= MAX_OTHER_FACTOR_BITS - 1
  644. #ifdef DEBUG
  645. struct {
  646. long mnanb, mnab, manb, mab, mnc, mdq, mde, mds, mqh, mql;
  647. } fmq_stat;
  648. # define mincr(x) ++fmq_stat.x
  649. #else
  650. # define mincr(x) DO_NOTHING
  651. #endif
  652. fixed
  653. fixed_mult_quo(fixed signed_A, fixed B, fixed C)
  654. {
  655. /* First compute A * B in double-fixed precision. */
  656. ulong A = (signed_A < 0 ? -signed_A : signed_A);
  657. long msw;
  658. ulong lsw;
  659. ulong p1;
  660. if (B <= half_mask) {
  661. if (A <= half_mask) {
  662. ulong P = A * B;
  663. fixed Q = P / (ulong)C;
  664. mincr(mnanb);
  665. /* If A < 0 and the division isn't exact, take the floor. */
  666. return (signed_A >= 0 ? Q : Q * C == P ? -Q : ~Q /* -Q - 1 */);
  667. }
  668. /*
  669. * We might still have C <= half_mask, which we can
  670. * handle with a simpler algorithm.
  671. */
  672. lsw = (A & half_mask) * B;
  673. p1 = (A >> half_bits) * B;
  674. if (C <= half_mask) {
  675. fixed q0 = (p1 += lsw >> half_bits) / C;
  676. ulong rem = ((p1 - C * q0) << half_bits) + (lsw & half_mask);
  677. ulong q1 = rem / (ulong)C;
  678. fixed Q = (q0 << half_bits) + q1;
  679. mincr(mnc);
  680. /* If A < 0 and the division isn't exact, take the floor. */
  681. return (signed_A >= 0 ? Q : q1 * C == rem ? -Q : ~Q);
  682. }
  683. msw = p1 >> half_bits;
  684. mincr(manb);
  685. } else if (A <= half_mask) {
  686. p1 = A * (B >> half_bits);
  687. msw = p1 >> half_bits;
  688. lsw = A * (B & half_mask);
  689. mincr(mnab);
  690. } else { /* We have to compute all 4 products. :-( */
  691. ulong lo_A = A & half_mask;
  692. ulong hi_A = A >> half_bits;
  693. ulong lo_B = B & half_mask;
  694. ulong hi_B = B >> half_bits;
  695. ulong p1x = hi_A * lo_B;
  696. msw = hi_A * hi_B;
  697. lsw = lo_A * lo_B;
  698. p1 = lo_A * hi_B;
  699. if (p1 > max_ulong - p1x)
  700. msw += 1L << half_bits;
  701. p1 += p1x;
  702. msw += p1 >> half_bits;
  703. mincr(mab);
  704. }
  705. /* Finish up by adding the low half of p1 to the high half of lsw. */
  706. #if max_fixed < max_long
  707. p1 &= half_mask;
  708. #endif
  709. p1 <<= half_bits;
  710. if (p1 > max_ulong - lsw)
  711. msw++;
  712. lsw += p1;
  713. /*
  714. * Now divide the double-length product by C. Note that we know msw
  715. * < C (otherwise the quotient would overflow). Start by shifting
  716. * (msw,lsw) and C left until C >= 1 << (num_bits - 1).
  717. */
  718. {
  719. ulong denom = C;
  720. int shift = 0;
  721. #define bits_4th (num_bits / 4)
  722. if (denom < 1L << (num_bits - bits_4th)) {
  723. mincr(mdq);
  724. denom <<= bits_4th, shift += bits_4th;
  725. }
  726. #undef bits_4th
  727. #define bits_8th (num_bits / 8)
  728. if (denom < 1L << (num_bits - bits_8th)) {
  729. mincr(mde);
  730. denom <<= bits_8th, shift += bits_8th;
  731. }
  732. #undef bits_8th
  733. while (!(denom & (-1L << (num_bits - 1)))) {
  734. mincr(mds);
  735. denom <<= 1, ++shift;
  736. }
  737. msw = (msw << shift) + (lsw >> (num_bits - shift));
  738. lsw <<= shift;
  739. #if max_fixed < max_long
  740. lsw &= (1L << (sizeof(fixed) * 8)) - 1;
  741. #endif
  742. /* Compute a trial upper-half quotient. */
  743. {
  744. ulong hi_D = denom >> half_bits;
  745. ulong lo_D = denom & half_mask;
  746. ulong hi_Q = (ulong) msw / hi_D;
  747. /* hi_Q might be too high by 1 or 2, but it isn't too low. */
  748. ulong p0 = hi_Q * hi_D;
  749. ulong p1 = hi_Q * lo_D;
  750. ulong hi_P;
  751. while ((hi_P = p0 + (p1 >> half_bits)) > msw ||
  752. (hi_P == msw && ((p1 & half_mask) << half_bits) > lsw)
  753. ) { /* hi_Q was too high by 1. */
  754. --hi_Q;
  755. p0 -= hi_D;
  756. p1 -= lo_D;
  757. mincr(mqh);
  758. }
  759. p1 = (p1 & half_mask) << half_bits;
  760. if (p1 > lsw)
  761. msw--;
  762. lsw -= p1;
  763. msw -= hi_P;
  764. /* Now repeat to get the lower-half quotient. */
  765. msw = (msw << half_bits) + (lsw >> half_bits);
  766. #if max_fixed < max_long
  767. lsw &= half_mask;
  768. #endif
  769. lsw <<= half_bits;
  770. {
  771. ulong lo_Q = (ulong) msw / hi_D;
  772. long Q;
  773. p1 = lo_Q * lo_D;
  774. p0 = lo_Q * hi_D;
  775. while ((hi_P = p0 + (p1 >> half_bits)) > msw ||
  776. (hi_P == msw && ((p1 & half_mask) << half_bits) > lsw)
  777. ) { /* lo_Q was too high by 1. */
  778. --lo_Q;
  779. p0 -= hi_D;
  780. p1 -= lo_D;
  781. mincr(mql);
  782. }
  783. Q = (hi_Q << half_bits) + lo_Q;
  784. return (signed_A >= 0 ? Q : p0 | p1 ? ~Q /* -Q - 1 */ : -Q);
  785. }
  786. }
  787. }
  788. }
  789. #else /* use doubles */
  790. /*
  791. * Compute A * B / C as above using doubles. If floating point is
  792. * reasonably fast, this is much faster than the fixed-point algorithm.
  793. */
  794. fixed
  795. fixed_mult_quo(fixed signed_A, fixed B, fixed C)
  796. {
  797. /*
  798. * Check whether A * B will fit in the mantissa of a double.
  799. */
  800. #define MAX_OTHER_FACTOR (1L << MAX_OTHER_FACTOR_BITS)
  801. if (B < MAX_OTHER_FACTOR || any_abs(signed_A) < MAX_OTHER_FACTOR) {
  802. #undef MAX_OTHER_FACTOR
  803. /*
  804. * The product fits, so a straightforward double computation
  805. * will be exact.
  806. */
  807. return (fixed)floor((double)signed_A * B / C);
  808. } else {
  809. /*
  810. * The product won't fit. However, the approximate product will
  811. * only be off by at most +/- 1/2 * (1 << ROUND_BITS) because of
  812. * rounding. If we add 1 << ROUND_BITS to the value of the product
  813. * (i.e., 1 in the least significant bit of the mantissa), the
  814. * result is always greater than the correct product by between 1/2
  815. * and 3/2 * (1 << ROUND_BITS). We know this is less than C:
  816. * because of the 'if' just above, we know that B >=
  817. * MAX_OTHER_FACTOR; since B <= C, we know C >= MAX_OTHER_FACTOR;
  818. * and because of the #if that chose between the two
  819. * implementations, we know that C >= 2 * (1 << ROUND_BITS). Hence,
  820. * the quotient after dividing by C will be at most 1 too large.
  821. */
  822. fixed q =
  823. (fixed)floor(((double)signed_A * B + (1L << ROUND_BITS)) / C);
  824. /*
  825. * Compute the remainder R. If the quotient was correct,
  826. * 0 <= R < C. If the quotient was too high, -C <= R < 0.
  827. */
  828. if (signed_A * B - q * C < 0)
  829. --q;
  830. return q;
  831. }
  832. }
  833. #endif
  834. #undef MAX_OTHER_FACTOR_BITS
  835. #undef ROUND_BITS
  836. #undef num_bits
  837. #undef half_bits
  838. #undef half_mask
  839. /* Trace calls on sqrt when debugging. */
  840. double
  841. gs_sqrt(double x, const char *file, int line)
  842. {
  843. if (gs_debug_c('~')) {
  844. dprintf3("[~]sqrt(%g) at %s:%d\n", x, (const char *)file, line);
  845. dflush();
  846. }
  847. return orig_sqrt(x);
  848. }
  849. /*
  850. * Define sine and cosine functions that take angles in degrees rather than
  851. * radians, and that are implemented efficiently on machines with slow
  852. * (or no) floating point.
  853. */
  854. #if USE_FPU < 0 /****** maybe should be <= 0 ? ***** */
  855. #define sin0 0.00000000000000000
  856. #define sin1 0.01745240643728351
  857. #define sin2 0.03489949670250097
  858. #define sin3 0.05233595624294383
  859. #define sin4 0.06975647374412530
  860. #define sin5 0.08715574274765817
  861. #define sin6 0.10452846326765346
  862. #define sin7 0.12186934340514748
  863. #define sin8 0.13917310096006544
  864. #define sin9 0.15643446504023087
  865. #define sin10 0.17364817766693033
  866. #define sin11 0.19080899537654480
  867. #define sin12 0.20791169081775931
  868. #define sin13 0.22495105434386498
  869. #define sin14 0.24192189559966773
  870. #define sin15 0.25881904510252074
  871. #define sin16 0.27563735581699916
  872. #define sin17 0.29237170472273671
  873. #define sin18 0.30901699437494740
  874. #define sin19 0.32556815445715670
  875. #define sin20 0.34202014332566871
  876. #define sin21 0.35836794954530027
  877. #define sin22 0.37460659341591201
  878. #define sin23 0.39073112848927377
  879. #define sin24 0.40673664307580015
  880. #define sin25 0.42261826174069944
  881. #define sin26 0.43837114678907740
  882. #define sin27 0.45399049973954675
  883. #define sin28 0.46947156278589081
  884. #define sin29 0.48480962024633706
  885. #define sin30 0.50000000000000000
  886. #define sin31 0.51503807491005416
  887. #define sin32 0.52991926423320490
  888. #define sin33 0.54463903501502708
  889. #define sin34 0.55919290347074679
  890. #define sin35 0.57357643635104605
  891. #define sin36 0.58778525229247314
  892. #define sin37 0.60181502315204827
  893. #define sin38 0.61566147532565829
  894. #define sin39 0.62932039104983739
  895. #define sin40 0.64278760968653925
  896. #define sin41 0.65605902899050728
  897. #define sin42 0.66913060635885824
  898. #define sin43 0.68199836006249848
  899. #define sin44 0.69465837045899725
  900. #define sin45 0.70710678118654746
  901. #define sin46 0.71933980033865108
  902. #define sin47 0.73135370161917046
  903. #define sin48 0.74314482547739413
  904. #define sin49 0.75470958022277201
  905. #define sin50 0.76604444311897801
  906. #define sin51 0.77714596145697090
  907. #define sin52 0.78801075360672190
  908. #define sin53 0.79863551004729283
  909. #define sin54 0.80901699437494745
  910. #define sin55 0.81915204428899180
  911. #define sin56 0.82903757255504174
  912. #define sin57 0.83867056794542394
  913. #define sin58 0.84804809615642596
  914. #define sin59 0.85716730070211222
  915. #define sin60 0.86602540378443860
  916. #define sin61 0.87461970713939574
  917. #define sin62 0.88294759285892688
  918. #define sin63 0.89100652418836779
  919. #define sin64 0.89879404629916704
  920. #define sin65 0.90630778703664994
  921. #define sin66 0.91354545764260087
  922. #define sin67 0.92050485345244037
  923. #define sin68 0.92718385456678731
  924. #define sin69 0.93358042649720174
  925. #define sin70 0.93969262078590832
  926. #define sin71 0.94551857559931674
  927. #define sin72 0.95105651629515353
  928. #define sin73 0.95630475596303544
  929. #define sin74 0.96126169593831889
  930. #define sin75 0.96592582628906831
  931. #define sin76 0.97029572627599647
  932. #define sin77 0.97437006478523525
  933. #define sin78 0.97814760073380558
  934. #define sin79 0.98162718344766398
  935. #define sin80 0.98480775301220802
  936. #define sin81 0.98768834059513777
  937. #define sin82 0.99026806874157036
  938. #define sin83 0.99254615164132198
  939. #define sin84 0.99452189536827329
  940. #define sin85 0.99619469809174555
  941. #define sin86 0.99756405025982420
  942. #define sin87 0.99862953475457383
  943. #define sin88 0.99939082701909576
  944. #define sin89 0.99984769515639127
  945. #define sin90 1.00000000000000000
  946. private const double sin_table[361] =
  947. {
  948. sin0,
  949. sin1, sin2, sin3, sin4, sin5, sin6, sin7, sin8, sin9, sin10,
  950. sin11, sin12, sin13, sin14, sin15, sin16, sin17, sin18, sin19, sin20,
  951. sin21, sin22, sin23, sin24, sin25, sin26, sin27, sin28, sin29, sin30,
  952. sin31, sin32, sin33, sin34, sin35, sin36, sin37, sin38, sin39, sin40,
  953. sin41, sin42, sin43, sin44, sin45, sin46, sin47, sin48, sin49, sin50,
  954. sin51, sin52, sin53, sin54, sin55, sin56, sin57, sin58, sin59, sin60,
  955. sin61, sin62, sin63, sin64, sin65, sin66, sin67, sin68, sin69, sin70,
  956. sin71, sin72, sin73, sin74, sin75, sin76, sin77, sin78, sin79, sin80,
  957. sin81, sin82, sin83, sin84, sin85, sin86, sin87, sin88, sin89, sin90,
  958. sin89, sin88, sin87, sin86, sin85, sin84, sin83, sin82, sin81, sin80,
  959. sin79, sin78, sin77, sin76, sin75, sin74, sin73, sin72, sin71, sin70,
  960. sin69, sin68, sin67, sin66, sin65, sin64, sin63, sin62, sin61, sin60,
  961. sin59, sin58, sin57, sin56, sin55, sin54, sin53, sin52, sin51, sin50,
  962. sin49, sin48, sin47, sin46, sin45, sin44, sin43, sin42, sin41, sin40,
  963. sin39, sin38, sin37, sin36, sin35, sin34, sin33, sin32, sin31, sin30,
  964. sin29, sin28, sin27, sin26, sin25, sin24, sin23, sin22, sin21, sin20,
  965. sin19, sin18, sin17, sin16, sin15, sin14, sin13, sin12, sin11, sin10,
  966. sin9, sin8, sin7, sin6, sin5, sin4, sin3, sin2, sin1, sin0,
  967. -sin1, -sin2, -sin3, -sin4, -sin5, -sin6, -sin7, -sin8, -sin9, -sin10,
  968. -sin11, -sin12, -sin13, -sin14, -sin15, -sin16, -sin17, -sin18, -sin19, -sin20,
  969. -sin21, -sin22, -sin23, -sin24, -sin25, -sin26, -sin27, -sin28, -sin29, -sin30,
  970. -sin31, -sin32, -sin33, -sin34, -sin35, -sin36, -sin37, -sin38, -sin39, -sin40,
  971. -sin41, -sin42, -sin43, -sin44, -sin45, -sin46, -sin47, -sin48, -sin49, -sin50,
  972. -sin51, -sin52, -sin53, -sin54, -sin55, -sin56, -sin57, -sin58, -sin59, -sin60,
  973. -sin61, -sin62, -sin63, -sin64, -sin65, -sin66, -sin67, -sin68, -sin69, -sin70,
  974. -sin71, -sin72, -sin73, -sin74, -sin75, -sin76, -sin77, -sin78, -sin79, -sin80,
  975. -sin81, -sin82, -sin83, -sin84, -sin85, -sin86, -sin87, -sin88, -sin89, -sin90,
  976. -sin89, -sin88, -sin87, -sin86, -sin85, -sin84, -sin83, -sin82, -sin81, -sin80,
  977. -sin79, -sin78, -sin77, -sin76, -sin75, -sin74, -sin73, -sin72, -sin71, -sin70,
  978. -sin69, -sin68, -sin67, -sin66, -sin65, -sin64, -sin63, -sin62, -sin61, -sin60,
  979. -sin59, -sin58, -sin57, -sin56, -sin55, -sin54, -sin53, -sin52, -sin51, -sin50,
  980. -sin49, -sin48, -sin47, -sin46, -sin45, -sin44, -sin43, -sin42, -sin41, -sin40,
  981. -sin39, -sin38, -sin37, -sin36, -sin35, -sin34, -sin33, -sin32, -sin31, -sin30,
  982. -sin29, -sin28, -sin27, -sin26, -sin25, -sin24, -sin23, -sin22, -sin21, -sin20,
  983. -sin19, -sin18, -sin17, -sin16, -sin15, -sin14, -sin13, -sin12, -sin11, -sin10,
  984. -sin9, -sin8, -sin7, -sin6, -sin5, -sin4, -sin3, -sin2, -sin1, -sin0
  985. };
  986. double
  987. gs_sin_degrees(double ang)
  988. {
  989. int ipart;
  990. if (is_fneg(ang))
  991. ang = 180 - ang;
  992. ipart = (int)ang;
  993. if (ipart >= 360) {
  994. int arem = ipart % 360;
  995. ang -= (ipart - arem);
  996. ipart = arem;
  997. }
  998. return
  999. (ang == ipart ? sin_table[ipart] :
  1000. sin_table[ipart] + (sin_table[ipart + 1] - sin_table[ipart]) *
  1001. (ang - ipart));
  1002. }
  1003. double
  1004. gs_cos_degrees(double ang)
  1005. {
  1006. int ipart;
  1007. if (is_fneg(ang))
  1008. ang = 90 - ang;
  1009. else
  1010. ang += 90;
  1011. ipart = (int)ang;
  1012. if (ipart >= 360) {
  1013. int arem = ipart % 360;
  1014. ang -= (ipart - arem);
  1015. ipart = arem;
  1016. }
  1017. return
  1018. (ang == ipart ? sin_table[ipart] :
  1019. sin_table[ipart] + (sin_table[ipart + 1] - sin_table[ipart]) *
  1020. (ang - ipart));
  1021. }
  1022. void
  1023. gs_sincos_degrees(double ang, gs_sincos_t * psincos)
  1024. {
  1025. psincos->sin = gs_sin_degrees(ang);
  1026. psincos->cos = gs_cos_degrees(ang);
  1027. psincos->orthogonal =
  1028. (is_fzero(psincos->sin) || is_fzero(psincos->cos));
  1029. }
  1030. #else /* we have floating point */
  1031. static const int isincos[5] =
  1032. {0, 1, 0, -1, 0};
  1033. /* GCC with -ffast-math compiles ang/90. as ang*(1/90.), losing precission.
  1034. * This doesn't happen when the numeral is replaced with a non-const variable.
  1035. * So we define the variable to work around the GCC problem.
  1036. */
  1037. static double const_90_degrees = 90.;
  1038. double
  1039. gs_sin_degrees(double ang)
  1040. {
  1041. double quot = ang / const_90_degrees;
  1042. if (floor(quot) == quot) {
  1043. /*
  1044. * We need 4.0, rather than 4, here because of non-ANSI compilers.
  1045. * The & 3 is because quot might be negative.
  1046. */
  1047. return isincos[(int)fmod(quot, 4.0) & 3];
  1048. }
  1049. return sin(ang * (M_PI / 180));
  1050. }
  1051. double
  1052. gs_cos_degrees(double ang)
  1053. {
  1054. double quot = ang / const_90_degrees;
  1055. if (floor(quot) == quot) {
  1056. /* See above re the following line. */
  1057. return isincos[((int)fmod(quot, 4.0) & 3) + 1];
  1058. }
  1059. return cos(ang * (M_PI / 180));
  1060. }
  1061. void
  1062. gs_sincos_degrees(double ang, gs_sincos_t * psincos)
  1063. {
  1064. double quot = ang / const_90_degrees;
  1065. if (floor(quot) == quot) {
  1066. /* See above re the following line. */
  1067. int quads = (int)fmod(quot, 4.0) & 3;
  1068. psincos->sin = isincos[quads];
  1069. psincos->cos = isincos[quads + 1];
  1070. psincos->orthogonal = true;
  1071. } else {
  1072. double arad = ang * (M_PI / 180);
  1073. psincos->sin = sin(arad);
  1074. psincos->cos = cos(arad);
  1075. psincos->orthogonal = false;
  1076. }
  1077. }
  1078. #endif /* USE_FPU */
  1079. /*
  1080. * Define an atan2 function that returns an angle in degrees and uses
  1081. * the PostScript quadrant rules. Note that it may return
  1082. * gs_error_undefinedresult.
  1083. */
  1084. int
  1085. gs_atan2_degrees(double y, double x, double *pangle)
  1086. {
  1087. if (y == 0) { /* on X-axis, special case */
  1088. if (x == 0)
  1089. return_error(gs_error_undefinedresult);
  1090. *pangle = (x < 0 ? 180 : 0);
  1091. } else {
  1092. double result = atan2(y, x) * radians_to_degrees;
  1093. if (result < 0)
  1094. result += 360;
  1095. *pangle = result;
  1096. }
  1097. return 0;
  1098. }