-Поиск по дневнику

Поиск сообщений в rss_thedaily_wtf

 -Подписка по e-mail

 

 -Постоянные читатели

 -Статистика

Статистика LiveInternet.ru: показано количество хитов и посетителей
Создан: 06.04.2008
Записей:
Комментариев:
Написано: 0


CodeSOD: We All Float Down Here…

Понедельник, 29 Июня 2015 г. 13:30 + в цитатник

When Maarten first saw the utility function below, he couldnt imagine why converting a number from float to double required a string intermediate. Fortunately, whoever wrote this code followed best practices: their comment not only explained what the code is doing, it also explained why.

Pennywise in the sewer


/**
	 * This method converts a float to a double.
	 * Because the model uses doubles in calculations while the matrices holds floats.
	 * @param number
	 * The float value to convert to a double
	 * @param accurate
	 * Flag to specify whether to use an accurate conversion from float to double
	 * or to use a less accurate conversion. Accurate means strings will be used
	 * what may result in a bit slower performance. Not accurate means typecasting
	 * will be used, this result in a fault since a double has a higher precision
	 * then a float.
	 */
	 double floatToDouble(float number, boolean accurate) {
	 	if (accurate) {
	 		return Double.parseDouble(Float.toString(number));
	 	}
	 	return number;
	 }

While Maarten appreciates the authors effort, hes not entirely convinced that comments alone can a sensible method make&

[Advertisement] Use NuGet or npm? Check out ProGet, the easy-to-use package repository that lets you host and manage your own personal or enterprise-wide NuGet feeds and npm repositories. It's got an impressively-featured free edition, too!

http://thedailywtf.com/articles/we-all-float-down-here

Метки:  

 

Добавить комментарий:
Текст комментария: смайлики

Проверка орфографии: (найти ошибки)

Прикрепить картинку:

 Переводить URL в ссылку
 Подписаться на комментарии
 Подписать картинку