Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1/4 1/8 1/16 1/32
- int cents = num % 100;
- int dollars = (num - cents) / 100;
- printf("%d.%02d", dollars, cents);
- #include <stdio.h>
- int main()
- {
- printf("Mapping 100 numbers between 0 and 1 ");
- printf("to their hexadecimal exponential form (HEF).n");
- printf("Most of them do not equal their HEFs. That means ");
- printf("that their representations as floats ");
- printf("differ from their actual values.n");
- double f = 0.01;
- int i;
- for (i = 0; i < 100; i++) {
- printf("%1.2f -> %an",f*i,f*i);
- }
- printf("Printing 128 'float-compatible' numbers ");
- printf("together with their HEFs for comparison.n");
- f = 0x1p-7; // ==0.0071825
- for (i = 0; i < 0x80; i++) {
- printf("%1.7f -> %an",f*i,f*i);
- }
- return 0;
- }
- DECLARE @Float1 float, @Float2 float, @Float3 float, @Float4 float;
- SET @Float1 = 54;
- SET @Float2 = 3.1;
- SET @Float3 = 0 + @Float1 + @Float2;
- SELECT @Float3 - @Float1 - @Float2 AS "Should be 0";
- Should be 0
- ----------------------
- 1.13797860024079E-15
- DECLARE @Fixed1 decimal(8,4), @Fixed2 decimal(8,4), @Fixed3 decimal(8,4);
- SET @Fixed1 = 54;
- SET @Fixed2 = 0.03;
- SET @Fixed3 = 1 * @Fixed1 / @Fixed2;
- SELECT @Fixed3 / @Fixed1 * @Fixed2 AS "Should be 1";
- Should be 1
- ---------------------------------------
- 0.99999999999999900
Add Comment
Please, Sign In to add comment