← Back to index
|
Original Bugzilla link
Bug 2906 – writef problem with formatting floating point
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-04-27T16:49:00Z
Last change time
2015-06-09T01:27:58Z
Assigned to
bugzilla
Creator
bugzilla
Comments
Comment #0
by bugzilla — 2009-04-27T16:49:18Z
The following code: import std.stdio ; import std.date ; int main ( string[] args ) { invariant n = 1000000000L ; invariant delta = 1.0 / n ; invariant startTime = getUTCtime ( ) ; real sum = 0.0 ; for ( auto i = 1L ; i <= n ; ++i ) { invariant x = ( i - 0.5 ) * delta ; sum += 1.0 / ( 1.0 + x * x ) ; } invariant pi = 4.0 * sum * delta ; invariant elapseTime = ( cast (real) ( getUTCtime ( ) - startTime ) ) / ticksPerSecond ; writefln ( "==== D Sequential pi = %f" , pi ) ; writefln ( "==== D Sequential iteration count = %d" , n ) ; writefln ( "==== D Sequential elapse = %f" , elapseTime ) ; writefln ( "==== D Sequential elapse = %s" , elapseTime ) ; printf ( "==== D Sequential elapse = %Lg\n" , elapseTime ) ; return 0 ; } Produces the output: ==== D Sequential pi = -88796093704866379077000000000000000000000000.000000 ==== D Sequential iteration count = 1000000000 ==== D Sequential elapse = -1204799831137578238800000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000.000000 ==== D Sequential elapse = -1.2048e+142 ==== D Sequential elapse = 110.718 writefln() is incorrectly formatting reals with the %f and %s formats.
Comment #1
by andrei — 2009-04-28T18:09:31Z
Fixed in svn.
Comment #2
by braddr — 2009-04-28T23:16:31Z
Andrei, would you add unit tests for this so that it doesn't regress? :)
Comment #3
by andrei — 2009-04-29T14:35:38Z
Added unittest.