diff --git a/ftoa.c b/ftoa.c new file mode 100644 index 0000000..fe42114 --- /dev/null +++ b/ftoa.c @@ -0,0 +1,43 @@ + + +#include +void flot(char* p, float x) +{ + int n,i=0,k=0; + n=(int)x; + while(n>0) + { + x/=10; + n=(int)x; + i++; + } + *(p+i) = '.'; + x *= 10; + n = (int)x; + x = x-n; + while(n>0) + { + if(k == i) + k++; + *(p+k)=48+n; + x *= 10; + n = (int)x; + x = x-n; + k++; + } + *(p+k) = '\0'; +} + +int main() +{ + float x; + char a[20]={}; + char* p=a; + printf("Enter the float value."); + scanf("%f",&x); + flot(p,x); + printf("The value=%s",p); + getchar(); + return 0; +} + diff --git a/src/test/scala/ExamplesNoCompressed.scala b/src/test/scala/ExamplesNoCompressed.scala index 506b559..d16d0aa 100644 --- a/src/test/scala/ExamplesNoCompressed.scala +++ b/src/test/scala/ExamplesNoCompressed.scala @@ -161,4 +161,12 @@ class ExamplesNoCompressed extends FreeSpec with PropertyChecks with Matchers { """.trim.stripMargin } +// "double" in { +// Run( "tests/double.hex" ) shouldBe +// """ +// |true +// |true +// """.trim.stripMargin +// } + } \ No newline at end of file diff --git a/tests/double.c b/tests/double.c index b2233df..1d898e6 100644 --- a/tests/double.c +++ b/tests/double.c @@ -25,5 +25,12 @@ printb( int b ) { void main() { - printb( 3.4 + 5.6 == 9.0 ); + double a = 3.4; + double b = 5.6; + double c = 7.8; + + printb( a + b == 9.0 ); +// printb( 3.4 - 5.6 == -2.2 ); +// printb( 3.4 * 5.6 == 19.04 ); +// printb( 3.4 / 5.6 == 0.607142857 ); } \ No newline at end of file diff --git a/tests/double.hex b/tests/double.hex index 9bf390b..a0f1758 100644 --- a/tests/double.hex +++ b/tests/double.hex @@ -17,14 +17,20 @@ Hex dump of section '.text': 0x00010160 03340100 13010101 67800000 130101fe .4......g....... 0x00010170 233c1100 23388100 13040102 93070500 #<..#8.......... 0x00010180 2326f4fe 8327c4fe 9b870700 63880700 #&...'......c... - 0x00010190 b7070100 9387071f 6f00c000 b7070100 ........o....... - 0x000101a0 9387871f 13850700 eff09ff4 eff05ff9 .............._. + 0x00010190 b7070100 93870723 6f00c000 b7070100 .......#o....... + 0x000101a0 93878723 13850700 eff09ff4 eff05ff9 ...#.........._. 0x000101b0 13000000 83308101 03340101 13010102 .....0...4...... - 0x000101c0 67800000 130101ff 23341100 23308100 g.......#4..#0.. - 0x000101d0 13040101 13051000 eff05ff9 13000000 .........._..... - 0x000101e0 83308100 03340100 13010101 67800000 .0...4......g... + 0x000101c0 67800000 130101fe 233c1100 23388100 g.......#<..#8.. + 0x000101d0 13040102 b7070100 87b70724 2734f4fe ...........$'4.. + 0x000101e0 b7070100 87b78724 2730f4fe 073784fe .......$'0...7.. + 0x000101f0 873704fe 5377f702 b7070100 87b70725 .7..Sw.........% + 0x00010200 d327f7a2 b337f000 93f7f70f 9b870700 .'...7.......... + 0x00010210 13850700 eff09ff5 13000000 83308101 .............0.. + 0x00010220 03340101 13010102 67800000 .4......g... Hex dump of section '.rodata': - 0x000101f0 74727565 00000000 66616c73 6500 true....false. + 0x00010230 74727565 00000000 66616c73 65000000 true....false... + 0x00010240 33333333 33330b40 66666666 66661640 333333.@ffffff.@ + 0x00010250 00000000 00002240 ......"@