www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2906] New: writef problem with formatting floating point

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2906

           Summary: writef problem with formatting floating point
           Product: D
           Version: 2.030
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: bugzilla digitalmars.com


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.


-- 
Apr 27 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2906


andrei metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #1 from andrei metalanguage.com  2009-04-28 18:09 -------
Fixed in svn.


-- 
Apr 28 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2906


braddr puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |




------- Comment #2 from braddr puremagic.com  2009-04-28 23:16 -------
Andrei, would you add unit tests for this so that it doesn't regress? :)


-- 
Apr 28 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2906


andrei metalanguage.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |FIXED




------- Comment #3 from andrei metalanguage.com  2009-04-29 14:35 -------
Added unittest.


-- 
Apr 29 2009