| | |
double and float......
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
It's better to put the code directly in your post if it's short. The problem is that floating-point values aren't always exact, so you can't reliably test for equality. The usual fix for your problem is to do a "close enough" test using the difference of the two values and a suitably small epsilon value:
c Syntax (Toggle Plain Text)
#include <stdio.h> #include <math.h> static double floating_epsilon ( int precision ) { double result = 0.1; while ( --precision >= 0 ) result /= 10; return result; } int main ( void ) { float a = 1.1; double b = 1.1; if ( fabs ( a - b ) <= floating_epsilon ( 1 ) ) printf("Both are equal\n"); else printf("Both of them are not equal\n"); return 0; }
![]() |
Similar Threads
Other Threads in the C Forum
- Previous Thread: converting string[][] to float[]
- Next Thread: subtract 2 signed bianry numbers
| Thread Tools | Search this Thread |
adobe ansi api array arrays asterisks bash binarysearch calculate centimeter char convert copyanyfile copyimagefile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic fflush file fork frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators infiniteloop initialization interest km linked linkedlist linux linuxsegmentationfault list locate logical_drives match matrix meter microsoft motherboard multi mysql number open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer pointers posix power probleminc program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling scripting segmentationfault send shape socketprograming stack standard strchr string strings structures suggestions systemcall test testautomation unix user variable voidmain() wab win32api windows.h





