this si a competitive programming problem , give mea c++ solution and explain it well : 
IEEE754 Emulator
Time limit: 2000 ms
Memory limit: 512 MB

The IEEE 754 single-precision floating-point format is a 32-bit binary format that represents real numbers. These 32 bits are divided into three distinct parts:


1. Sign bit (1 bit):

The first bit (bit 31) indicates the sign of the number.
0 means the number is positive.
1 means the number is negative.

2. Exponent (8 bits):

The next 8 bits (bits 30 to 23) represent the exponent of the number.
The exponent is stored using a "biased" format, with a bias of 127. This means the actual exponent is calculated as: 
exponent
=
exponent bits value
−
127
exponent=exponent bits value−127.
For example, if the exponent bits are 10000001 (which is 129 in decimal), the actual exponent is 
129
−
127
=
2
129−127=2.

3. Fraction (mantissa) (23 bits):

The last 23 bits (bits 22 to 0) represent the fraction (mantissa) of the number.
The IEEE 754 format assumes a "normalized" representation where the leading bit is always 1 and is not stored (it is implied). Therefore, the actual value of the mantissa is: 
1
+
fraction bits
1+fraction bits
The fraction bits represent the fractional part of the number.


The value of the floating-point number is computed as 
(
−
1
)
sign
×
2
(
exponent
−
127
)
×
(
1
+
mantissa
)
(−1) 
sign
 ×2 
(exponent−127)
 ×(1+mantissa) .


For the hexadecimal value 40490fdb = 01000000010010010000111111011011:

Sign bit: 0 (positive)
Exponent: 10000000 (decimal 128, so 
actual exponent
=
128
−
127
=
1
actual exponent=128−127=1)
Mantissa: 10010010000111111011011 (which corresponds to a fraction slightly greater than 1)

This combination represents the number 3.1415927410125732421875 (approximately).


The addition and multiplication rules (with a calculator for testing) are explained in the following links:

Addition and substraction
Multiplication

Note: Consider the following special rules:

x
×
∞
→
∞
 for 
x
>
0
x×∞→∞ for x>0.
x
×
(
−
∞
)
→
∞
 for 
x
<
0
x×(−∞)→∞ for x<0.
∞
−
∞
→
NaN
∞−∞→NaN.
0
×
∞
→
NaN
0×∞→NaN.
x
×
NaN
→
NaN
x×NaN→NaN.
0
×
(
−
0
)
→
−
0
0×(−0)→−0.
(Might add some more)

To compute approximated values of functions we will assume that we must store first an hexadecimal value and then the result of many commands which (possibly) use some previously stored values.


One of the most interesting commands is Fused Multiply-Add (FMA), which receives 3 floating point values 
a
a, 
b
b and 
c
c and computes 
a
×
b
+
c
a×b+c with only one rounding step. This command differs with multiplying and then adding the values since multiplication does one rounding step and addition makes another one, so precision might be lost due to this.


We will start with a single hexadecimal value 
C
[
0
]
C[0] and then many commands follow:

Look-Up Table (LUT): Consider that many hexadecimal values are stored in many tables 
L
U
T
[
i
]
LUT[i] of size 
2
k
i
2 
k 
i
​
 
  for some 
k
i
≥
1
k 
i
​
 ≥1. Then, if we execute a LUT command L i j b, then we must compute the integer value of the bits in positions 
[
j
,
j
+
b
−
1
]
[j,j+b−1] from 
C
[
0
]
C[0] (let this value be 
m
a
s
k
mask) and the answer will be 
L
U
T
[
i
]
[
m
a
s
k
]
LUT[i][mask]. It must be guaranteed that both 
b
≤
k
i
b≤k 
i
​
  and 
0
≤
j
≤
j
+
b
−
1
<
32
0≤j≤j+b−1<32.
NAND Gate: If we execute a NAND command N i j, then we must compute the Bitwise NAND of the values 
C
[
i
]
C[i] and 
C
[
j
]
C[j].
Fused Multiply Add: If we execute an FMA command F i j k, then we must compute 
C
[
i
]
×
C
[
j
]
+
C
[
k
]
C[i]×C[j]+C[k].
Constant declaration: If we execute a Constant command C h, then we must store the hexadecimal 
h
h.

Given 
C
[
0
]
C[0], the LUTs and the commands to execute, your task is to compute the value stored by the last command.


Standard input

The first line of input contains an integer 
T
T, the number of test cases.

The following lines describe 
T
T test cases.

The first line of each test case contains an hexadecimal value 
C
[
0
]
C[0] that represents a single-precision floating point value.

The second line of each test case contains an integer 
L
L, the number of LUTs to read.

The 
p
p-th of the following 
L
L lines contains an integer 
2
k
i
2 
k 
i
​
 
  followed by 
2
k
i
2 
k 
i
​
 
  hexadecimals that represent single-precision floating point values.

The next line of each test contains an integer 
Q
Q, the number of commands to execute.

The 
n
n-th of the following 
Q
Q lines contains a command:


L i j b: Store the corresponding LUT result for this command. It is guaranteed that 
0
≤
i
<
L
0≤i<L, 
0
≤
j
≤
j
+
b
−
1
<
32
0≤j≤j+b−1<32 and 
b
≤
k
i
b≤k 
i
​
 .
N i j: Store the corresponding NAND result for this command. It is guaranteed that 
0
≤
i
,
j
<
n
0≤i,j<n.
F i j k: Store the corresponding FMA result for this command. It is guaranteed that 
0
≤
i
,
j
,
k
<
n
0≤i,j,k<n.
C h: Store the corresponding Constant result for this command. It is guaranteed that 
h
h is an hexadecimal value.

Standard output

Print 
T
T lines, the 
i
i-th line must contain the value stored by the last command of the 
i
i-th test case.


Constraints and notes

1
≤
T
≤
1
0
5
1≤T≤10 
5
 .
1
≤
∑
i
=
1
T
Q
i
≤
1
0
5
1≤ 
i=1
∑
T
​
 Q 
i
​
 ≤10 
5
 , which means that the total number of commands doesn't exceed 
1
0
5
10 
5
 .
The sum of the sizes of LUTs across the test cases doesn't exceed 
1
0
5
10 
5
 .
Input	Output
4
00000000
0
3
C BF800000
C 40800000
F 2 0 1
3F800000
0
3
C BF800000
C 40800000
F 2 0 1
40490fdb
0
3
C BF800000
C 40800000
F 2 0 1
BF800001
0
3
C BF800000
C 40800000
F 2 0 1
bf800000
40400000
41390fdb
c0a00001
5
00000000
0
5
C 80000000
N 0 1
N 0 2
N 2 1
N 3 4
12345678
0
5
C 80000000
N 0 1
N 0 2
N 2 1
N 3 4
CCCCCCCC
0
5
C 80000000
N 0 1
N 0 2
N 2 1
N 3 4
CDEF0123
0
5
C 80000000
N 0 1
N 0 2
N 2 1
N 3 4
01020304
0
5
C 80000000
N 0 1
N 0 2
N 2 1
N 3 4
80000000
92345678
4ccccccc
4def0123
81020304