sdlStrtod function

double sdlStrtod(
  1. String? str,
  2. Pointer<Pointer<Int8>> endp
)

Parse a double from a string.

This function makes fewer guarantees than the C runtime strtod:

  • Only decimal notation is guaranteed to be supported. The handling of scientific and hexadecimal notation is unspecified.
  • Whether or not INF and NAN can be parsed is unspecified.
  • The precision of the result is unspecified.

\param str The null-terminated string to read. Must not be NULL. \param endp If not NULL, the address of the first invalid character (i.e. the next character after the parsed number) will be written to this pointer. \returns The parsed double, or 0 if no number could be parsed.

\threadsafety It is safe to call this function from any thread.

\since This function is available since SDL 3.1.3.

\sa SDL_atoi \sa SDL_atof \sa SDL_strtol \sa SDL_strtoll \sa SDL_strtoul \sa SDL_strtoull

extern SDL_DECLSPEC double SDLCALL SDL_strtod(const char *str, char **endp)

Implementation

double sdlStrtod(String? str, Pointer<Pointer<Int8>> endp) {
  final sdlStrtodLookupFunction = libSdl3.lookupFunction<
      Double Function(Pointer<Utf8> str, Pointer<Pointer<Int8>> endp),
      double Function(
          Pointer<Utf8> str, Pointer<Pointer<Int8>> endp)>('SDL_strtod');
  final strPointer = str != null ? str.toNativeUtf8() : nullptr;
  final result = sdlStrtodLookupFunction(strPointer, endp);
  calloc.free(strPointer);
  return result;
}