Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have a function similar to float8in_internal_null( ) for Integer types? #1023

Closed
M4rcxs opened this issue Jul 11, 2023 · 2 comments
Closed
Labels
question Further information is requested

Comments

@M4rcxs
Copy link
Contributor

M4rcxs commented Jul 11, 2023

I am currently developing a function that converts a list of values to integers. In the case of float types, we have the convenient float8in_internal_null() function at toFloatList(), which returns the appropriate float value if the conversion is successful, but returns NULL if the conversion of a list element fails.

However, when working with integers and using the atoi() function, I encountered a limitation. Unlike float8in_internal_null(), atoi() does not return NULL when it fails to convert an element of the list to an integer. Instead, it returns 0.

Is there an alternative function within some library in AGE, that can help me achieve the desired behavior of returning NULL when a conversion to an integer is not possible? I would appreciate any guidance on this matter.

The PR of the toFloatList() function implemented is #1016

@M4rcxs M4rcxs added the question Further information is requested label Jul 11, 2023
@Amr-Shams
Copy link

I believe you encountered this problem to make a double check about the input what if it is zero and how to differentiate between the input is zero or the conversion was valid if that's the case then you can use an end pointer passed to the Atoi() then check in case of successful conversion the end pointer points to the null terminated string-"\0" other than this will be an error or un successful conversion.

@kenwoon
Copy link
Contributor

kenwoon commented Jul 12, 2023

I don't think there is an alternative function available in the AGE library. In your function, it may be easier if you just change the condition when using atoi() to check for the value 0 instead of NULL since the function will always return 0 when it fails in the conversion. For example:

atoi(string) ? atoi(string) : NULL;

@M4rcxs M4rcxs closed this as completed Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants