MagickCore  7.1.1-43
Convert, Edit, Or Compose Bitmap Images
quantum-private.h
1 /*
2  Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
3  dedicated to making software imaging solutions freely available.
4 
5  You may not use this file except in compliance with the License. You may
6  obtain a copy of the License at
7 
8  https://imagemagick.org/script/license.php
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  MagickCore quantum inline methods.
17 */
18 #ifndef MAGICKCORE_QUANTUM_PRIVATE_H
19 #define MAGICKCORE_QUANTUM_PRIVATE_H
20 
21 #include "MagickCore/memory_.h"
22 #include "MagickCore/cache.h"
23 #include "MagickCore/image-private.h"
24 #include "MagickCore/pixel-accessor.h"
25 
26 #if defined(__cplusplus) || defined(c_plusplus)
27 extern "C" {
28 #endif
29 
30 typedef struct _QuantumState
31 {
32  double
33  inverse_scale;
34 
35  unsigned int
36  pixel;
37 
38  size_t
39  bits;
40 
41  const unsigned int
42  *mask;
43 } QuantumState;
44 
46 {
47  size_t
48  depth,
49  quantum;
50 
51  QuantumFormatType
52  format;
53 
54  double
55  minimum,
56  maximum,
57  scale;
58 
59  size_t
60  pad;
61 
62  MagickBooleanType
63  min_is_white,
64  pack;
65 
66  QuantumAlphaType
67  alpha_type;
68 
69  size_t
70  number_threads;
71 
73  **pixels;
74 
75  size_t
76  extent;
77 
78  EndianType
79  endian;
80 
82  state;
83 
85  *semaphore;
86 
87  size_t
88  signature;
89 };
90 
91 extern MagickPrivate void
92  ResetQuantumState(QuantumInfo *);
93 
94 static inline MagickSizeType GetQuantumRange(const size_t depth)
95 {
96  MagickSizeType
97  one;
98 
99  size_t
100  max_depth;
101 
102  if (depth == 0)
103  return(0);
104  one=1;
105  max_depth=8*sizeof(MagickSizeType);
106  return((MagickSizeType) ((one << (MagickMin(depth,max_depth)-1))+
107  ((one << (MagickMin(depth,max_depth)-1))-1)));
108 }
109 
110 static inline float HalfToSinglePrecision(const unsigned short half)
111 {
112 #define ExponentBias (127-15)
113 #define ExponentMask (0x7c00U)
114 #define ExponentShift 23
115 #define SignBitShift 31
116 #define SignificandShift 13
117 #define SignificandMask (0x00000400U)
118 
119  typedef union _SinglePrecision
120  {
121  unsigned int
122  fixed_point;
123 
124  float
125  single_precision;
126  } SinglePrecision;
127 
128  SinglePrecision
129  map;
130 
131  unsigned int
132  exponent,
133  significand,
134  sign_bit,
135  value;
136 
137  /*
138  The IEEE 754 standard specifies half precision as having:
139 
140  Sign bit: 1 bit
141  Exponent width: 5 bits
142  Significand precision: 11 (10 explicitly stored)
143  */
144  sign_bit=(unsigned int) ((half >> 15) & 0x00000001);
145  exponent=(unsigned int) ((half >> 10) & 0x0000001f);
146  significand=(unsigned int) (half & 0x000003ff);
147  if (exponent == 0)
148  {
149  if (significand == 0)
150  value=sign_bit << SignBitShift;
151  else
152  {
153  while ((significand & SignificandMask) == 0)
154  {
155  significand<<=1;
156  exponent--;
157  }
158  exponent++;
159  significand&=(~SignificandMask);
160  exponent+=ExponentBias;
161  value=(sign_bit << SignBitShift) | (exponent << ExponentShift) |
162  (significand << SignificandShift);
163  }
164  }
165  else
166  if (exponent == SignBitShift)
167  {
168  value=(sign_bit << SignBitShift) | 0x7f800000;
169  if (significand != 0)
170  value|=(significand << SignificandShift);
171  }
172  else
173  {
174  exponent+=ExponentBias;
175  significand<<=SignificandShift;
176  value=(sign_bit << SignBitShift) | (exponent << ExponentShift) |
177  significand;
178  }
179  map.fixed_point=value;
180  return(map.single_precision);
181 }
182 
183 static inline unsigned char *PopCharPixel(const unsigned char pixel,
184  unsigned char *magick_restrict pixels)
185 {
186  *pixels++=pixel;
187  return(pixels);
188 }
189 
190 static inline unsigned char *PopLongPixel(const EndianType endian,
191  const unsigned int pixel,unsigned char *magick_restrict pixels)
192 {
193  unsigned int
194  quantum;
195 
196  quantum=(unsigned int) pixel;
197  if (endian == LSBEndian)
198  {
199  *pixels++=(unsigned char) (quantum);
200  *pixels++=(unsigned char) (quantum >> 8);
201  *pixels++=(unsigned char) (quantum >> 16);
202  *pixels++=(unsigned char) (quantum >> 24);
203  return(pixels);
204  }
205  *pixels++=(unsigned char) (quantum >> 24);
206  *pixels++=(unsigned char) (quantum >> 16);
207  *pixels++=(unsigned char) (quantum >> 8);
208  *pixels++=(unsigned char) (quantum);
209  return(pixels);
210 }
211 
212 static inline unsigned char *PopShortPixel(const EndianType endian,
213  const unsigned short pixel,unsigned char *magick_restrict pixels)
214 {
215  unsigned int
216  quantum;
217 
218  quantum=pixel;
219  if (endian == LSBEndian)
220  {
221  *pixels++=(unsigned char) (quantum);
222  *pixels++=(unsigned char) (quantum >> 8);
223  return(pixels);
224  }
225  *pixels++=(unsigned char) (quantum >> 8);
226  *pixels++=(unsigned char) (quantum);
227  return(pixels);
228 }
229 
230 static inline const unsigned char *PushCharPixel(
231  const unsigned char *magick_restrict pixels,
232  unsigned char *magick_restrict pixel)
233 {
234  *pixel=(*pixels++);
235  return(pixels);
236 }
237 
238 static inline const unsigned char *PushLongPixel(const EndianType endian,
239  const unsigned char *magick_restrict pixels,
240  unsigned int *magick_restrict pixel)
241 {
242  unsigned int
243  quantum;
244 
245  if (endian == LSBEndian)
246  {
247  quantum=((unsigned int) *pixels++);
248  quantum|=((unsigned int) *pixels++ << 8);
249  quantum|=((unsigned int) *pixels++ << 16);
250  quantum|=((unsigned int) *pixels++ << 24);
251  *pixel=quantum;
252  return(pixels);
253  }
254  quantum=((unsigned int) *pixels++ << 24);
255  quantum|=((unsigned int) *pixels++ << 16);
256  quantum|=((unsigned int) *pixels++ << 8);
257  quantum|=((unsigned int) *pixels++);
258  *pixel=quantum;
259  return(pixels);
260 }
261 
262 static inline const unsigned char *PushShortPixel(const EndianType endian,
263  const unsigned char *magick_restrict pixels,
264  unsigned short *magick_restrict pixel)
265 {
266  unsigned int
267  quantum;
268 
269  if (endian == LSBEndian)
270  {
271  quantum=(unsigned int) *pixels++;
272  quantum|=(unsigned int) (*pixels++ << 8);
273  *pixel=(unsigned short) (quantum & 0xffff);
274  return(pixels);
275  }
276  quantum=(unsigned int) (*pixels++ << 8);
277  quantum|=(unsigned int) *pixels++;
278  *pixel=(unsigned short) (quantum & 0xffff);
279  return(pixels);
280 }
281 
282 static inline const unsigned char *PushFloatPixel(const EndianType endian,
283  const unsigned char *magick_restrict pixels,
284  MagickFloatType *magick_restrict pixel)
285 {
286  union
287  {
288  unsigned int
289  unsigned_value;
290 
291  MagickFloatType
292  float_value;
293  } quantum;
294 
295  if (endian == LSBEndian)
296  {
297  quantum.unsigned_value=((unsigned int) *pixels++);
298  quantum.unsigned_value|=((unsigned int) *pixels++ << 8);
299  quantum.unsigned_value|=((unsigned int) *pixels++ << 16);
300  quantum.unsigned_value|=((unsigned int) *pixels++ << 24);
301  *pixel=quantum.float_value;
302  return(pixels);
303  }
304  quantum.unsigned_value=((unsigned int) *pixels++ << 24);
305  quantum.unsigned_value|=((unsigned int) *pixels++ << 16);
306  quantum.unsigned_value|=((unsigned int) *pixels++ << 8);
307  quantum.unsigned_value|=((unsigned int) *pixels++);
308  *pixel=quantum.float_value;
309  return(pixels);
310 }
311 
312 static inline Quantum ScaleAnyToQuantum(const QuantumAny quantum,
313  const QuantumAny range)
314 {
315  if (quantum > range)
316  return(QuantumRange);
317 #if !defined(MAGICKCORE_HDRI_SUPPORT)
318  return((Quantum) ((double) QuantumRange*(quantum*
319  PerceptibleReciprocal((double) range))+0.5));
320 #else
321  return((Quantum) ((double) QuantumRange*(quantum*
322  PerceptibleReciprocal((double) range))));
323 #endif
324 }
325 
326 static inline QuantumAny ScaleQuantumToAny(const Quantum quantum,
327  const QuantumAny range)
328 {
329 #if !defined(MAGICKCORE_HDRI_SUPPORT)
330  return((QuantumAny) ((double) range*quantum/QuantumRange));
331 #else
332  if ((IsNaN(quantum) != 0) || (quantum <= 0.0f))
333  return((QuantumAny) 0UL);
334  if ((range*(double) quantum/(double) QuantumRange) >= 18446744073709551615.0)
335  return((QuantumAny) MagickULLConstant(18446744073709551615));
336  return((QuantumAny) (range*(double) quantum/(double) QuantumRange+0.5));
337 #endif
338 }
339 
340 #if (MAGICKCORE_QUANTUM_DEPTH == 8)
341 static inline Quantum ScaleCharToQuantum(const unsigned char value)
342 {
343  return((Quantum) value);
344 }
345 
346 static inline Quantum ScaleLongToQuantum(const unsigned int value)
347 {
348 #if !defined(MAGICKCORE_HDRI_SUPPORT)
349  return((Quantum) ((value)/16843009UL));
350 #else
351  return((Quantum) (value/16843009.0));
352 #endif
353 }
354 
355 static inline Quantum ScaleLongLongToQuantum(const MagickSizeType value)
356 {
357 #if !defined(MAGICKCORE_HDRI_SUPPORT)
358  return((Quantum) (value/MagickULLConstant(72340172838076673)));
359 #else
360  return((Quantum) (value/72340172838076673.0));
361 #endif
362 }
363 
364 static inline Quantum ScaleMapToQuantum(const MagickRealType value)
365 {
366  if (value <= 0.0)
367  return((Quantum) 0);
368  if (value >= MaxMap)
369  return(QuantumRange);
370 #if !defined(MAGICKCORE_HDRI_SUPPORT)
371  return((Quantum) (value+0.5));
372 #else
373  return((Quantum) value);
374 #endif
375 }
376 
377 static inline unsigned int ScaleQuantumToLong(const Quantum quantum)
378 {
379 #if !defined(MAGICKCORE_HDRI_SUPPORT)
380  return((unsigned int) (16843009UL*quantum));
381 #else
382  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
383  return(0U);
384  if ((16843009.0*quantum) >= 4294967295.0)
385  return(4294967295UL);
386  return((unsigned int) (16843009.0*quantum+0.5));
387 #endif
388 }
389 
390 static inline MagickSizeType ScaleQuantumToLongLong(const Quantum quantum)
391 {
392 #if !defined(MAGICKCORE_HDRI_SUPPORT)
393  return((MagickSizeType) (MagickULLConstant(72340172838076673)*quantum));
394 #else
395  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
396  return(0UL);
397  if ((72340172838076673.0*quantum) >= 18446744073709551615.0)
398  return(MagickULLConstant(18446744073709551615));
399  return((MagickSizeType) (72340172838076673.0*quantum+0.5));
400 #endif
401 }
402 
403 static inline unsigned int ScaleQuantumToMap(const Quantum quantum)
404 {
405  if (quantum >= (Quantum) MaxMap)
406  return((unsigned int) MaxMap);
407 #if !defined(MAGICKCORE_HDRI_SUPPORT)
408  return((unsigned int) quantum);
409 #else
410  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
411  return(0U);
412  return((unsigned int) (quantum+0.5));
413 #endif
414 }
415 
416 static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
417 {
418 #if !defined(MAGICKCORE_HDRI_SUPPORT)
419  return((unsigned short) (257UL*quantum));
420 #else
421  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
422  return(0);
423  if ((257.0*quantum) >= 65535.0)
424  return(65535);
425  return((unsigned short) (257.0*quantum+0.5));
426 #endif
427 }
428 
429 static inline Quantum ScaleShortToQuantum(const unsigned short value)
430 {
431 #if !defined(MAGICKCORE_HDRI_SUPPORT)
432  return((Quantum) ((value+128U)/257U));
433 #else
434  return((Quantum) (value/257.0));
435 #endif
436 }
437 #elif (MAGICKCORE_QUANTUM_DEPTH == 16)
438 static inline Quantum ScaleCharToQuantum(const unsigned char value)
439 {
440 #if !defined(MAGICKCORE_HDRI_SUPPORT)
441  return((Quantum) (257U*value));
442 #else
443  return((Quantum) (257.0*value));
444 #endif
445 }
446 
447 static inline Quantum ScaleLongToQuantum(const unsigned int value)
448 {
449 #if !defined(MAGICKCORE_HDRI_SUPPORT)
450  return((Quantum) ((value)/MagickULLConstant(65537)));
451 #else
452  return((Quantum) (value/65537.0));
453 #endif
454 }
455 
456 static inline Quantum ScaleLongLongToQuantum(const MagickSizeType value)
457 {
458 #if !defined(MAGICKCORE_HDRI_SUPPORT)
459  return((Quantum) ((value)/MagickULLConstant(281479271743489)));
460 #else
461  return((Quantum) (value/281479271743489.0));
462 #endif
463 }
464 
465 static inline Quantum ScaleMapToQuantum(const MagickRealType value)
466 {
467  if (value <= 0.0)
468  return((Quantum) 0);
469  if (value >= MaxMap)
470  return(QuantumRange);
471 #if !defined(MAGICKCORE_HDRI_SUPPORT)
472  return((Quantum) (value+0.5));
473 #else
474  return((Quantum) value);
475 #endif
476 }
477 
478 static inline unsigned int ScaleQuantumToLong(const Quantum quantum)
479 {
480 #if !defined(MAGICKCORE_HDRI_SUPPORT)
481  return((unsigned int) (65537UL*quantum));
482 #else
483  if ((IsNaN(quantum) != 0) || (quantum <= 0.0f))
484  return(0U);
485  if ((65537.0*(double) quantum) >= 4294967295.0)
486  return(4294967295U);
487  return((unsigned int) (65537.0*(double) quantum+0.5));
488 #endif
489 }
490 
491 static inline MagickSizeType ScaleQuantumToLongLong(const Quantum quantum)
492 {
493 #if !defined(MAGICKCORE_HDRI_SUPPORT)
494  return((MagickSizeType) (MagickULLConstant(281479271743489)*quantum));
495 #else
496  if ((IsNaN(quantum) != 0) || (quantum <= 0.0f))
497  return(0UL);
498  if ((281479271743489.0*(double) quantum) >= 18446744073709551615.0)
499  return(MagickULLConstant(18446744073709551615));
500  return((MagickSizeType) (281479271743489.0*(double) quantum+0.5));
501 #endif
502 }
503 
504 static inline unsigned int ScaleQuantumToMap(const Quantum quantum)
505 {
506  if (quantum >= (Quantum) MaxMap)
507  return((unsigned int) MaxMap);
508 #if !defined(MAGICKCORE_HDRI_SUPPORT)
509  return((unsigned int) quantum);
510 #else
511  if ((IsNaN(quantum) != 0) || (quantum <= 0.0f))
512  return(0U);
513  return((unsigned int) (quantum+0.5f));
514 #endif
515 }
516 
517 static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
518 {
519 #if !defined(MAGICKCORE_HDRI_SUPPORT)
520  return((unsigned short) quantum);
521 #else
522  if ((IsNaN(quantum) != 0) || (quantum <= 0.0f))
523  return(0);
524  if (quantum >= 65535.0f)
525  return(65535);
526  return((unsigned short) (quantum+0.5f));
527 #endif
528 }
529 
530 static inline Quantum ScaleShortToQuantum(const unsigned short value)
531 {
532  return((Quantum) value);
533 }
534 #elif (MAGICKCORE_QUANTUM_DEPTH == 32)
535 static inline Quantum ScaleCharToQuantum(const unsigned char value)
536 {
537 #if !defined(MAGICKCORE_HDRI_SUPPORT)
538  return((Quantum) (16843009UL*value));
539 #else
540  return((Quantum) (16843009.0*value));
541 #endif
542 }
543 
544 static inline Quantum ScaleLongToQuantum(const unsigned int value)
545 {
546  return((Quantum) value);
547 }
548 
549 static inline Quantum ScaleLongLongToQuantum(const MagickSizeType value)
550 {
551 #if !defined(MAGICKCORE_HDRI_SUPPORT)
552  return((Quantum) ((value)/MagickULLConstant(4294967297)));
553 #else
554  return((Quantum) (value/4294967297.0));
555 #endif
556 }
557 
558 static inline Quantum ScaleMapToQuantum(const MagickRealType value)
559 {
560  if (value <= 0.0)
561  return((Quantum) 0);
562  if (value >= (Quantum) MaxMap)
563  return(QuantumRange);
564 #if !defined(MAGICKCORE_HDRI_SUPPORT)
565  return((Quantum) (65537.0*value+0.5));
566 #else
567  return((Quantum) (65537.0*value));
568 #endif
569 }
570 
571 static inline unsigned int ScaleQuantumToLong(const Quantum quantum)
572 {
573 #if !defined(MAGICKCORE_HDRI_SUPPORT)
574  return((unsigned int) quantum);
575 #else
576  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
577  return(0U);
578  if ((quantum) >= 4294967295.0)
579  return(4294967295);
580  return((unsigned int) (quantum+0.5));
581 #endif
582 }
583 
584 static inline MagickSizeType ScaleQuantumToLongLong(const Quantum quantum)
585 {
586 #if !defined(MAGICKCORE_HDRI_SUPPORT)
587  return((MagickSizeType) (MagickULLConstant(4294967297)*quantum));
588 #else
589  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
590  return(0UL);
591  if ((4294967297.0*quantum) >= 18446744073709551615.0)
592  return(MagickULLConstant(18446744073709551615));
593  return((MagickSizeType) (4294967297.0*quantum+0.5));
594 #endif
595 }
596 
597 static inline unsigned int ScaleQuantumToMap(const Quantum quantum)
598 {
599  if ((quantum/65537) >= (Quantum) MaxMap)
600  return((unsigned int) MaxMap);
601 #if !defined(MAGICKCORE_HDRI_SUPPORT)
602  return((unsigned int) ((quantum+MagickULLConstant(32768))/
603  MagickULLConstant(65537)));
604 #else
605  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
606  return(0U);
607  return((unsigned int) (quantum/65537.0+0.5));
608 #endif
609 }
610 
611 static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
612 {
613 #if !defined(MAGICKCORE_HDRI_SUPPORT)
614  return((unsigned short) ((quantum+MagickULLConstant(32768))/
615  MagickULLConstant(65537)));
616 #else
617  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
618  return(0);
619  if ((quantum/65537.0) >= 65535.0)
620  return(65535);
621  return((unsigned short) (quantum/65537.0+0.5));
622 #endif
623 }
624 
625 static inline Quantum ScaleShortToQuantum(const unsigned short value)
626 {
627 #if !defined(MAGICKCORE_HDRI_SUPPORT)
628  return((Quantum) (65537UL*value));
629 #else
630  return((Quantum) (65537.0*value));
631 #endif
632 }
633 #elif (MAGICKCORE_QUANTUM_DEPTH == 64)
634 static inline Quantum ScaleCharToQuantum(const unsigned char value)
635 {
636  return((Quantum) (72340172838076673.0*value));
637 }
638 
639 static inline Quantum ScaleLongToQuantum(const unsigned int value)
640 {
641  return((Quantum) (4294967297.0*value));
642 }
643 
644 static inline Quantum ScaleLongLongToQuantum(const MagickSizeType value)
645 {
646  return((Quantum) (value));
647 }
648 
649 static inline Quantum ScaleMapToQuantum(const MagickRealType value)
650 {
651  if (value <= 0.0)
652  return((Quantum) 0);
653  if (value >= MaxMap)
654  return(QuantumRange);
655  return((Quantum) (281479271743489.0*value));
656 }
657 
658 static inline unsigned int ScaleQuantumToLong(const Quantum quantum)
659 {
660  return((unsigned int) (quantum/4294967297.0+0.5));
661 }
662 
663 static inline MagickSizeType ScaleQuantumToLongLong(const Quantum quantum)
664 {
665 #if !defined(MAGICKCORE_HDRI_SUPPORT)
666  return((MagickSizeType) quantum);
667 #else
668  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
669  return(0UL);
670  if (quantum >= 18446744073709551615.0)
671  return(MagickULLConstant(18446744073709551615));
672  return((MagickSizeType) (quantum+0.5));
673 #endif
674 }
675 
676 static inline unsigned int ScaleQuantumToMap(const Quantum quantum)
677 {
678  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
679  return(0U);
680  if ((quantum/281479271743489.0) >= MaxMap)
681  return((unsigned int) MaxMap);
682  return((unsigned int) (quantum/281479271743489.0+0.5));
683 }
684 
685 static inline unsigned short ScaleQuantumToShort(const Quantum quantum)
686 {
687  if ((IsNaN(quantum) != 0) || (quantum <= 0.0))
688  return(0);
689  if ((quantum/281479271743489.0) >= 65535.0)
690  return(65535);
691  return((unsigned short) (quantum/281479271743489.0+0.5));
692 }
693 
694 static inline Quantum ScaleShortToQuantum(const unsigned short value)
695 {
696  return((Quantum) (281479271743489.0*value));
697 }
698 #endif
699 
700 static inline unsigned short SinglePrecisionToHalf(const float value)
701 {
702  typedef union _SinglePrecision
703  {
704  unsigned int
705  fixed_point;
706 
707  float
708  single_precision;
709  } SinglePrecision;
710 
711  int
712  exponent;
713 
714  SinglePrecision
715  map;
716 
717  unsigned int
718  significand,
719  sign_bit;
720 
721  unsigned short
722  half;
723 
724  /*
725  The IEEE 754 standard specifies half precision as having:
726 
727  Sign bit: 1 bit
728  Exponent width: 5 bits
729  Significand precision: 11 (10 explicitly stored)
730  */
731  map.single_precision=value;
732  sign_bit=(map.fixed_point >> 16) & 0x00008000;
733  exponent=(int) ((map.fixed_point >> ExponentShift) & 0x000000ff)-ExponentBias;
734  significand=map.fixed_point & 0x007fffff;
735  if (exponent <= 0)
736  {
737  int
738  shift;
739 
740  if (exponent < -10)
741  return((unsigned short) sign_bit);
742  significand=significand | 0x00800000;
743  shift=(int) (14-exponent);
744  significand=(unsigned int) ((significand+((1U << (shift-1))-1)+
745  ((significand >> shift) & 0x01)) >> shift);
746  return((unsigned short) (sign_bit | significand));
747  }
748  else
749  if (exponent == (0xff-ExponentBias))
750  {
751  if (significand == 0)
752  return((unsigned short) (sign_bit | ExponentMask));
753  else
754  {
755  significand>>=SignificandShift;
756  half=(unsigned short) (sign_bit | significand |
757  (significand == 0) | ExponentMask);
758  return(half);
759  }
760  }
761  significand=significand+((significand >> SignificandShift) & 0x01)+0x00000fff;
762  if ((significand & 0x00800000) != 0)
763  {
764  significand=0;
765  exponent++;
766  }
767  if (exponent > 30)
768  {
769  float
770  alpha;
771 
772  int
773  i;
774 
775  /*
776  Float overflow.
777  */
778  alpha=1.0e10;
779  for (i=0; i < 10; i++)
780  alpha*=alpha;
781  return((unsigned short) (sign_bit | ExponentMask));
782  }
783  half=(unsigned short) (sign_bit | ((unsigned int) exponent << 10) |
784  (significand >> SignificandShift));
785  return(half);
786 }
787 
788 #if defined(__cplusplus) || defined(c_plusplus)
789 }
790 #endif
791 
792 #endif
_QuantumInfo
Definition: quantum-private.h:45
_MemoryInfo
Definition: memory.c:163
SemaphoreInfo
Definition: semaphore.c:60
_QuantumState
Definition: quantum-private.h:30