c - How would I convert a char array to a float and check its range? -


I am creating an application in Microsoft Visual Studio 2012 and I have a function that takes four arrays and It has to return a single precision floating point number.

My job:

  token aa_func08 (four lexem []) {token t; / * Return of the literal token of the floating point * / double temp; / * Floating point value of character array * / temp = atof (lexeme); / * Floating point value * / if the character convert array ((FLT_MAX - floating the & lt; = FLT_EPSILON) || (temporary - FLT_MIN & lt; = FLT_EPSILON)) / * floating point value limit * / return aa_table Is out [es] (literally); / * An error token * / t.code = FPL_T; / * Set token code * / t.attribute.flt_value = (float) temporary; / * Set token integer value floating point literal value * / return t; / Floating Point Laikl Tokn return * /}  

I would like to see the float value than the maximum and minimum values ​​for the float data type, and I'd have to check the length.

If I pass:

  1,999999999999999911111111111111111111111111111111111111111111111111111111111111111  

production I've been chasing hope>

I hope to achieve: 2.000000

If I pass:

  999999999999999999999999999999999999999999999999999999999999999999999999999999999,0  

I hope to achieve: 99999999999999999999

If I pass:

  0,00000000000000000000000000000000000000000000000000000000000000000000000000000000001  

I hope to get: 0.000000000000000000

what Does anyone know how can I get such results or at least tell me in the right direction? Thanks!

Edit

For the first case, the result is indicated by 2.000000 32-bit float. The second two results only string lexem is being initially shortened to 20 characters. To summarize, if the term represents a valid boat , it is presented as a boat, but wordy If the wrong code represents , then the name (Out of range, missing numbers after decimal points etc.), then I return the first 20 characters of lexeme (actual < Code> float not).

You want to read it:

Especially you are not going "99 99 99 99 99 99 99 99 99" for receiving, or 20 digits of the exact number of float type (or more than two). Second, depending on how the values ​​change is likely to get you 1E-83 for "0.00000000000000000000000000000000000000000000000000000000000000000000000000000000001". You may also want to take a look at

, your examples do not match your goals, suggesting that one or another will cause disappointment if you have a string in 32-bit float type If you need to change then you will need to adhere to the boundaries of that format. If you need accurate (and behavioral) of your examples, you will need to type some types of custom numeric types.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -