ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


functions:atof

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
functions:atof [2017/03/21 16:00] – created korshunfunctions:atof [2017/04/17 15:33] (current) korshun
Line 4: Line 4:
  
 ===== Description ===== ===== Description =====
-Returns s converted to a fixed-point number. On error, returns 0.+Returns s parsed as a fixed-point number. If s cannot be parsed as a fixed-point number, returns 0. 
 + 
 +If s is too big or too small to fit into a fixed-point number, returns [[constants:INT_MAX]] with the sign of the input. 
 + 
 +Supports signs and [[:Number prefixes]]. 
 + 
 +<note important>This function parses the fractional part only up to the amount of digits that can be stored in a fixed-point number. This means that numbers with very long fractional parts will not be fully parsed, e.g. ''%%"0.12345678901234567890thisisnotanumberanymore!@#$^#$^$*%^*$"%%'' will parse successfully. 
 +</note> 
 + 
 +<note tip>To parse ints, use [[atoi]].</note> 
 + 
 +<note tip>For more flexibility in parsing and error handlinguse [[ParseFixed]].</note> 
 + 
 +===== Examples ===== 
 + 
 +<code> 
 +atof("123") -> 123.0 
 +atof("123.456") -> 123.456 
 +atof("0") -> 0 
 +atof("999999999999") -> 32767.99999 // Too big 
 +atof("-99999999999") -> -32767.99999 // Too small 
 +atof("not a number") -> 0 // Error 
 +atof("0xff.8") -> 255.5 // Hexadecimal prefix 
 +</code>
  
-See [[:Number parsing]] for features and examples. 
functions/atof.1490104814.txt.gz · Last modified: 2017/03/21 16:00 by korshun