1 | /* $Id: frexpf.cpp 96298 2022-08-18 14:28:28Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - No-CRT - frexpf().
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2022 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #define IPRT_NO_CRT_FOR_3RD_PARTY
|
---|
32 | #include "internal/nocrt.h"
|
---|
33 | #include <iprt/nocrt/math.h>
|
---|
34 | #include <iprt/assertcompile.h>
|
---|
35 | #include <iprt/nocrt/limits.h>
|
---|
36 |
|
---|
37 |
|
---|
38 | /* Similar to the fxtract instruction. */
|
---|
39 | #undef frexpf
|
---|
40 | float RT_NOCRT(frexpf)(float rfValue, int *piExp)
|
---|
41 | {
|
---|
42 | RTFLOAT32U Value;
|
---|
43 | AssertCompile(sizeof(Value) == sizeof(rfValue));
|
---|
44 | Value.r = rfValue;
|
---|
45 |
|
---|
46 | if (RTFLOAT32U_IS_NORMAL(&Value))
|
---|
47 | {
|
---|
48 | *piExp = (int)Value.s.uExponent - RTFLOAT32U_EXP_BIAS + 1;
|
---|
49 | Value.s.uExponent = RTFLOAT32U_EXP_BIAS - 1;
|
---|
50 | }
|
---|
51 | else if (RTFLOAT32U_IS_ZERO(&Value))
|
---|
52 | {
|
---|
53 | *piExp = 0;
|
---|
54 | return rfValue;
|
---|
55 | }
|
---|
56 | else if (RTFLOAT32U_IS_SUBNORMAL(&Value))
|
---|
57 | {
|
---|
58 | int iExp = -RTFLOAT32U_EXP_BIAS + 1;
|
---|
59 | uint32_t uFraction = Value.s.uFraction;
|
---|
60 | while (!(uFraction & RT_BIT_32(RTFLOAT32U_FRACTION_BITS)))
|
---|
61 | {
|
---|
62 | iExp--;
|
---|
63 | uFraction <<= 1;
|
---|
64 | }
|
---|
65 | Value.s.uFraction = uFraction;
|
---|
66 | Value.s.uExponent = RTFLOAT32U_EXP_BIAS - 1;
|
---|
67 | *piExp = iExp + 1;
|
---|
68 | }
|
---|
69 | else /* NaN, Inf */
|
---|
70 | {
|
---|
71 | *piExp = Value.s.fSign ? INT_MIN : INT_MAX;
|
---|
72 | return rfValue;
|
---|
73 | }
|
---|
74 | return Value.r;
|
---|
75 | }
|
---|
76 | RT_ALIAS_AND_EXPORT_NOCRT_SYMBOL(frexpf);
|
---|
77 |
|
---|