/******************************************************************************/ /* */ /* FILE: june.cpp */ /* */ /* I stumbled over quite an expressive double today */ /* ================================================ */ /* */ /* Compiled and tested with Visual C++ V6.0 */ /* */ /* V1.00 30-JUN-2001 P. Tellenbach http://www.heimetli.ch/ */ /* */ /******************************************************************************/ #include <iostream> struct { char ch ; double dbl ; } table[] = { { '\0', 0.07142857142857140 }, { ' ', 0.21428571428571400 }, { '!', 0.28571428571428600 }, { 'd', 0.35714285714285700 }, { 'e', 0.42857142857142900 }, { 'l', 0.64285714285714300 }, { 'o', 0.78571428571428600 }, { 'r', 0.85714285714285700 }, { 'w', 0.92857142857142800 }, { 'H', 1.00000000000000000 } }, *pt ; int main( ) { double lower, value = 0.956894131554267 ; for( ;; ) { for( pt = table, lower = 0.0; pt->dbl < value; pt++ ) lower = pt->dbl ; if( pt->ch == '\0' ) return 0 ; std::cout << pt->ch ; value = (value - lower) / (pt->dbl - lower) ; } }
Update 30. June 2021
This program compiles and runs without any changes.