| | |
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 |
#include * adobe ansi append array arrays asterisks bash binarysearch centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fgets file fork framework function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide include incrementoperators infiniteloop input interest intmain() iso kernel keyboard kilometer license linked linkedlist linux list lists locate looping lowest match matrix meter microsoft number oddnumber opendocumentformat opensource overwrite owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv recvblocked research reversing scripting segmentationfault sequential single socket socketprograming standard strchr string systemcall testing threads turboc unix user variable voidmain() wab whythiscodecausesegmentationfault windowsapi





