Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

FloatToString class  RSS feed

 
Stefan Geelen
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

on DoubleToString I saw a fast algorithm to convert a double to a String.

Has anyone a similar class to convert a Float to a String (did someone convert the double to string algorithm to a float to string algorithm) ?

Regards,

Stefan
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, don't have a direct answer to your question.

But I am curious: what do you need it for? Are you sure that the conversion is your performance bottleneck and that a factor of 2-4 would help? (BTW, I am not even sure that those numbers are still correct for JDK 1.4...)
 
Stefan Geelen
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

thanks for the reply. We did in the past some testing on double to string and the algorithm was indeed much faster than the toString method in the Double class (in SDK 1.3)

Now we want to convert the doubles to float in the application (as it only consumes 4 bytes instead of 8 for a double) and where wondering if there was a FloatToString algorithm like the one in the article (follow the URL).

We do not really have any performance problem, we just do not want to lose performance when switching to floats.

Stefan
 
Tim West
Ranch Hand
Posts: 539
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm gonna pre-empt Ilja:

Premature Optimisation



--Tim
[ June 01, 2004: Message edited by: Tim West ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stefan Geelen:
thanks for the reply. We did in the past some testing on double to string and the algorithm was indeed much faster than the toString method in the Double class (in SDK 1.3)

Now we want to convert the doubles to float in the application (as it only consumes 4 bytes instead of 8 for a double) and where wondering if there was a FloatToString algorithm like the one in the article (follow the URL).

We do not really have any performance problem, we just do not want to lose performance when switching to floats.
[/QB]


Switch to floats. Measure the performance impact. Measure your bottleneck. *Then* decide wether it's worth the effort to think about porting the convertions algorithm to floats.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!