You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Now we will compare some of the ToString values
183
+
// compare native to native - but parsing e-3 versus e-12 means 9 more loops thru the double multiplication where rounding can occur so this won't work for all numbers
Assert.Equal(dnum1Roslyn.ToString(),dnum2Native.ToString(),$"Comparing Roslyn parse and native parse tostring");
189
+
Assert.Equal(dnum1Native.ToString(),dnum2Roslyn.ToString(),$"Comparing Roslyn parse and native parse tostring");
190
+
Assert.Equal(dnum1Roslyn.ToString(),dnum1Native.ToString(),$"Comparing Roslyn to native using {num1}");
191
+
Assert.Equal(dnum2Roslyn.ToString(),dnum2Native.ToString(),$"Comparing Roslyn to natvie using {num2}");
177
192
}
178
193
179
194
[TestMethod]
@@ -198,48 +213,128 @@ public void Convert_HexInt()
198
213
}
199
214
200
215
[TestMethod]
216
+
201
217
publicvoidConvert_BoundaryValues()
202
218
{
203
-
doublevalMax=double.MaxValue;
204
-
stringnumMax=valMax.ToString();
205
-
doublevalMin=double.MinValue;
206
-
stringnumMin=valMin.ToString();
207
-
208
-
Assert.Equal(valMax,Convert.ToDouble(numMax));
209
-
Assert.Equal(valMin,Convert.ToDouble(numMin));
210
-
211
-
valMax=float.MaxValue;
212
-
numMax=valMax.ToString();
213
-
valMin=float.MinValue;
214
-
numMin=valMin.ToString();
215
-
216
-
Assert.Equal(valMax,Convert.ToDouble(numMax));
217
-
Assert.Equal(valMin,Convert.ToDouble(numMin));
219
+
//***
220
+
//* Boundary tests - tests of the min and max values for double, float and int's.
221
+
//* Note for double/float - the ToString() function is limited to a range around 2^64 and 2^-64 - otherwise you get a string of 'oor' or '-oor' (oor = out-of-range)
222
+
// Boundary tests for double/float include the numbers that are around the edge of where out-of-range is produced.
223
+
//***
224
+
225
+
conststringOUT_OF_RANGE="oor";// nanoPrintf can only print up to 2^64-2 as a max value for double/floating
226
+
conststringOUT_OF_RANGE_NEG="-oor";// nanoPrintf can only print down to -2^64+2 as a min value for double/floating
227
+
228
+
conststringDOUBLE_MAX_VAL="1.7976931348623157E+308";// will get 'oor' when printed
229
+
conststringDOUBLE_MAX_HEX="0x7FEFFFFFFFFFFFFF";// value from IEEE 574
230
+
conststringDOUBLE_MIN_VAL="-1.7976931348623157E+308";// will get '-oor' when printed
231
+
conststringDOUBLE_MIN_HEX="0xFFEFFFFFFFFFFFFF";// value from IEEE 574
232
+
conststringDOUBLE_ZERO_HEX="0x0000000000000000";
233
+
conststringDOUBLE_LARGEST_PRINT="1.84467440737095E+19";// this is the largest number you can ask for ToString() and get a response
234
+
conststringDOUBLE_LARGESTINVALID_PRINT="1.8446744073709552E+19";// first positive value that will get the response 'oor' when printed
235
+
conststringDOUBLE_SMALLEST_PRINT="-1.32585973029787E+19";// this is the smallest number you can ask for ToString() and get a response
236
+
conststringDOUBLE_SMALLESTINVALID_PRINT="-1.8446744073709552E+19";// first negative value that will get the response '-oor' when printed
237
+
238
+
conststringFLOAT_MAX_VAL="3.40282347E+38";
239
+
conststringFLOAT_MAX_HEX="0x7F7FFFFF";// will get 'oor' when printed
240
+
conststringFLOAT_MIN_VAL="-3.40282347E+38";
241
+
conststringFLOAT_MIN_HEX="0xFF7FFFFF";// will get '-oor' when printed
242
+
conststringFLOAT_ZERO_HEX="0x00000000";
243
+
conststringFLOAT_LARGEST_PRINT="1.844674E+19";// this is the largest number you can ask for ToString() and get a response
244
+
conststringFLOAT_LARGESTINVALID_PRINT="1.8446744E+19";// first positive value that will get the response 'oor' when printed
245
+
conststringFLOAT_SMALLEST_PRINT="-1.844674E+19";// this is the smallest number you can ask for ToString() and get a response
246
+
conststringFLOAT_SMALLESTINVALID_PRINT="-1.8446744E+19";// first negative value that will get the response '-oor' when printed
247
+
248
+
// boundary: double max
249
+
stringtime=DateTime.UtcNow.ToString("hh:mm:ss");
250
+
doubledoubleMax=double.MaxValue;
251
+
Assert.Equal(doubleMax.ToString(),OUT_OF_RANGE,"nanoPrintf returns oor for double > 2^64-2");
252
+
Assert.Equal(DoubleToHex(doubleMax),DOUBLE_MAX_HEX,"Hex value to double max value does not match");
253
+
Assert.Equal(DoubleToHex(Convert.ToDouble(DOUBLE_MAX_VAL)),DOUBLE_MAX_HEX,"Parsing double max value does not return correct hex value");
254
+
255
+
// boundary: double min
256
+
doubledoubleMin=double.MinValue;
257
+
Assert.Equal(doubleMin.ToString(),OUT_OF_RANGE_NEG,"nanoPrintf returns oor for double < -2^64+2");
258
+
Assert.Equal(DoubleToHex(doubleMin),DOUBLE_MIN_HEX,"Hex value to double min value does not match");
259
+
Assert.Equal(DoubleToHex(Convert.ToDouble(DOUBLE_MIN_VAL)),DOUBLE_MIN_HEX,"Parsing double min value does not return correct hex value");
260
+
261
+
// boundary: double zero
262
+
doubledoubleZero=0;// test that zero gets a zero exponent and a value like 1023 the exponent bias used in floating point math
263
+
Assert.Equal(doubleZero.ToString(),"0","ToString of a double with zero value formats incorrectly");
264
+
Assert.Equal(DoubleToHex(doubleZero),DOUBLE_ZERO_HEX,"Double with zero value returns the wrong hex value");
/// Converts the given double to a hexidecimal display - to be used to test boundary cases.
495
+
/// </summary>
496
+
/// <param name="f">The single (float) to convert.</param>
497
+
/// <returns>"+Infinity", "-Infinity", "NaN" or "0x[8 hex bytes]"</return>
498
+
publicstaticstringFloatToHex(floatf)
499
+
{
500
+
if(float.IsPositiveInfinity(f))
501
+
return"+Infinity";
502
+
if(float.IsNegativeInfinity(f))
503
+
return"-Infinity";
504
+
if(float.IsNaN(f))
505
+
return"NaN";
506
+
stringreturnValue=string.Format("0x{0:X8}",BitConverter.ToInt32(BitConverter.GetBytes(f),0));// CoreLibrary/mscorlib does not implement SingleToInt32Bits
return(ulong)NativeToInt64(value.Trim(),false,0,0,fromBase);// the interface use long for min/max, and uint64 is bigger. Setting min/max to 0/0 will cause the native code to calculate the largest value and return it as Int64 which when cast to UInt64 returns the larger numbers that a UInt64 can reach
0 commit comments