parser.cxx

changeset 54
8cc91ef94754
parent 53
9ef7e549391f
child 55
173956c1ac27
equal deleted inserted replaced
53:9ef7e549391f 54:8cc91ef94754
846 // table and returns it index if it doesn't find it there. 846 // table and returns it index if it doesn't find it there.
847 MustString (true); 847 MustString (true);
848 b->Write<word> (DH_PUSHSTRINGINDEX); 848 b->Write<word> (DH_PUSHSTRINGINDEX);
849 b->Write<word> (PushToStringTable (token.chars())); 849 b->Write<word> (PushToStringTable (token.chars()));
850 break; 850 break;
851 case TYPE_FLOAT: {
852 str floatstring;
853
854 MustNumber (true);
855 floatstring += token;
856
857 // Go after the decimal point
858 if (!PeekNext ().compare(".")) {
859 MustNext (".");
860 MustNumber (false);
861 floatstring += ".";
862 floatstring += token;
863 }
864
865 // TODO: Casting float to word causes the decimal to be lost.
866 // Find a way to store the number without such loss.
867 float val = atof (floatstring);
868 b->Write<word> (DH_PUSHNUMBER);
869 b->Write<word> (static_cast<word> ((val > 0) ? val : -val));
870 if (val < 0)
871 b->Write<word> (DH_UNARYMINUS);
872
873 // TODO: Keep this check after decimal loss is fixed, but make
874 // it a real precision loss check. 55.5123 -> 55.512299, this
875 // should probably be warned of.
876 float check = static_cast<float> (static_cast<word> (val));
877 if (val != check)
878 ParserWarning ("floating point number %f loses precision (-> %f)", val, check);
879 }
851 } 880 }
852 } 881 }
853 882
854 // Negate it now if desired 883 // Negate it now if desired
855 if (negate) 884 if (negate)

mercurial