@@ -67,7 +67,7 @@ struct Fp(uint size)
6767 enum scale = T(2 ) ^^ T.mant_dig;
6868 x = frexp(x, exp) * scale;
6969 }
70- auto dd = this .coefficient.view.leastSignificantFirst;
70+
7171 static if (T.mant_dig < 64 )
7272 {
7373 auto xx = cast (ulong )cast (long )x;
@@ -76,8 +76,12 @@ struct Fp(uint size)
7676 auto shift = ctlz(xx);
7777 exp -= shift + T.mant_dig + size - 64 ;
7878 xx <<= shift;
79+ this .coefficient = UInt! 64 (xx).rightExtend! (size - 64 );
80+ }
81+ else
82+ {
83+ this .coefficient = xx;
7984 }
80- dd[normalize ? $ - 1 : 0 ] = xx;
8185 }
8286 else
8387 static if (T.mant_dig == 64 )
@@ -88,8 +92,12 @@ struct Fp(uint size)
8892 auto shift = ctlz(xx);
8993 exp -= shift + T.mant_dig + size - 64 ;
9094 xx <<= shift;
95+ this .coefficient = UInt! 64 (xx).rightExtend! (size - 64 );
96+ }
97+ else
98+ {
99+ this .coefficient = xx;
91100 }
92- dd[normalize ? $ - 1 : 0 ] = xx;
93101 }
94102 else
95103 {
@@ -103,15 +111,22 @@ struct Fp(uint size)
103111 x *= scale;
104112 auto most = ulong (high);
105113 auto least = cast (ulong )x;
114+ version (LittleEndian )
115+ ulong [2 ] pair = [most, least];
116+ else
117+ ulong [2 ] pair = [least, most];
106118
107- dd[normalize ? $ - 1 : 1 ] = most;
108- dd[normalize ? $ - 2 : 0 ] = least;
109119 if (normalize)
110120 {
121+ this .coefficient = UInt! 128 (pair).rightExtend! (size - 128 );
111122 auto shift = most ? ctlz(most) : ctlz(least) + 64 ;
112123 exp -= shift + T.mant_dig + size - 64 * (1 + (T.mant_dig > 64 ));
113124 this .coefficient <<= shift;
114125 }
126+ else
127+ {
128+ this .coefficient = pair;
129+ }
115130 }
116131 if (! normalize)
117132 {
0 commit comments