Created
June 4, 2014 08:30
-
-
Save katlogic/9f43c36197421b8d09d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| proc c_sprintf(buf, frmt: cstring):int {.header: "<stdio.h>", | |
| importc: "sprintf", varargs, noSideEffect.} | |
| proc to_s(f: float): string = | |
| var buf: array [0..64, char] | |
| var n:int = c_sprintf(buf, "%.16g", f) | |
| for i in 0..n: | |
| if buf[i] == '.': return $buf | |
| buf[n] = '.' | |
| buf[n+1] = '0' | |
| buf[n+2] = '\0' | |
| result = $buf | |
| stdout.writeln(to_s(1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment