sharing everything

C Fast Casting Data Type

I have a problem when try to change data type form one to another in C. For example, I try to casting float data type to integer or from double to integer. In the last time, I use command (int)float_number. Because this process is slow, I try to searching about fast casting data type. We can use command lrint (convert from double to integer) and lrintf (convert from float to integer). This is my simple code to compare my old casting data and use fast casting data type (from c library). Create a new file (give name tes_casting.c). Copy this code to that file :

Compile this code with command :

gcc tes_casting.c -lm -o tes_casting

This is how to use and output from this program :

You can see, lrintf and lrint can speed up your casting algorithm. Converting float to integer with or without lrintf command can 100% faster than (int)float_numb.

My name is Toto Sugito. This is my notes when I try something. Maybe, this is NOT THE BEST SOLUTION for your problems. If you have other method or idea that better with my post, please share in this blog. Thank for visiting my site.

No Comments Yet

Leave a Reply

Your email address will not be published. Required fields are marked *



Bloggers - Meet Millions of Bloggers