473,385 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Truncation of fractions in floating-point literals

Hello,

In Control Panel, Regional Settings, set decimal point to something other then dot
,,.'' (ASCII 0x2E). Let it be comma (ASCII 0x2C) for example. Compile and run the
following code

=== BEGIN of test.c ===
#include <math.h>
#include <stdio.h>

main()
{
#pragma setlocale(".ACP")
printf("ANSI: %3g %3g %3g %3g %7g\n", 0.1, 0.9, 1.1, 1.9, pow(1.999, 10.0));
#pragma setlocale("C")
printf("C: %3g %3g %3g %3g %7g\n", 0.1, 0.9, 1.1, 1.9, pow(1.999, 10.0));
}
=== END of test.c ===

The program gives following result:

ANSI: 0 0 1 1 1
C: 0.1 0.9 1.1 1.9 1018.89

It looks that the lexical analizer internally uses setlocaled version of
atof()/sscanf() to retrieve value of the FP literals. This is strange bug in the
lexer. Such behaviour breaks elementary rules of ISO C standard. Moreover, it does
not generate any warnings/errors regardless of warning level.

Tested on all versions of CL from VS 6.0 SP5 to VS 2005 SP1.

-- best regards
Cezary Noweta
Jul 4 '07 #1
6 1955
Hi Cezary,
I reproduced your issue at my side. It indeed seems to be a product issue.
I need to confirm this with the product team, however the process may need
a long time. If I could not get a response within two business days, I will
file a product issue to them and let you know.

Thanks for your feedback. Have a nice day!

Best regards,
Charles Wang
Microsoft Online Community Support
================================================== ===
Get notification to my posts through email? Please refer to:
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications

If you are using Outlook Express, please make sure you clear the check box
"Tools/Options/Read: Get 300 headers at a time" to see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
================================================== ====
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
================================================== ====
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== ====


Jul 5 '07 #2
Hello,
I need to confirm this with the product team, however the process may need
a long time.
Thank you. Hopefuly, the bug is easy to omitting in a code, but under condition that
programmer know about it. Usually nobody assumes that compiler incorectly calculates
a value of literals. When pi == 3 and exp(1) == 2 results can be strange and nobody
knows why.

I'd like to inform that there are other strange behaviours (if not bugs) of the
compiler concerning character sets. I will describe CL 14.0 (from VS 2005 SP1). I'm
using English version of VS - not Asian ones. To illustrate the problems I've
attached two files. If they are deleted from my post then I will place their
description:

=== BEGIN OF test-ansi.c ===
#pragma setlocale(".932")

#define MSG_SPACE "Some Japanese DBCS text\n" \
"containing backslash\n" \
"as the trailing character"

main()
{
char *s = MSG_SPACE;
}
=== END OF test-ansi.c ===

=== BEGIN OF test-uni.c ===
The same as above test-ansi.c file, but encoded as UTF-16
=== END OF test-uni.c ===

My system codepage is 1250.

I will refer to the ISO C (9899:1999) which is the same as the ISO C++ in the
following case.

Compiling ,,test-ansi.c'' gives following warning:

test-ansi.c(9) : warning C4129: '' : unrecognized character escape sequence

According to ISO C ,,5.2.1.2 Multibyte characters'': <<While in the initial shift
state, all single-byte characters retain their usual interpretation and do not alter
the shift state. The interpretation for subsequent bytes in the sequence is a
function of the current shift state.>>

In ISO C ,,5.1.1.2 Translation phases'' states that conversion of escape sequences
occurs after preprocessing directives are executed. So preprocessor should know that
the string is in 932 DBCS and the backslash is a trailing char - not a leading one.

Adding the second backslash produce desired results. Fortunately CL 14.0 handles
UTF-16 files. However compiling ,,test-uni.c'' gives many of the following warning:

test-uni.c(9) : warning C4566: character represented by universal-character-name
'\u7A7A' cannot be represented in the current code page (1250)

which gives "??????????" string - not a 932 DBCS one.

As above, according to the ,,5.1.1.2 Translation phases'', <<5. Each source character
set member and escape sequence in character constants and string literals is
converted to the corresponding member of the execution character set; if there is no
corresponding member, it is converted to an implementation defined member other than
the null (wide) character.>>, which occurs _after_ preprocessing directives are
executed (phase 4.), so preprocessor should know that it should convert unicode
string to DBCS codepage 932 and not to SBCS 1250 codepage (which is my system
codepage).

-- best regards

Cezary Noweta
Jul 5 '07 #3
Hi Cezary,
Thank you very much for your feedback.

For the warning C4129, it seems to be Microsoft specific. It is explained
in this article:
C++ Character Constants
http://msdn2.microsoft.com/en-us/lib...f2(VS.80).aspx

"If the character following the backslash does not specify a legal escape
sequence, the result is implementation defined. In Microsoft C++, the
character following the backslash is taken literally, as though the escape
were not present, and a level 1 warning ("unrecognized character escape
sequence") is issued."

If you change "\•" to something like "\\", "\r", "\n", or "\t" etc, then
the warning will disappear. Just the character following the backslash
should be a legal escape sequence.

For the C4566 warning, you may refer to this article:
Compiler Warning (level 1) C4566
http://msdn2.microsoft.com/en-us/lib...07(VS.80).aspx

However it seemed that this article could not explain the C4566 error in
your scenario. I will also consult the product team on this issue.

If it is convenient for you, I recommend that you can give Microsoft
feedback directly via:
https://connect.microsoft.com/VisualStudio/Feedback

Best regards,
Charles Wang
Microsoft Online Community Support
================================================== ===
Get notification to my posts through email? Please refer to:
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications

If you are using Outlook Express, please make sure you clear the check box
"Tools/Options/Read: Get 300 headers at a time" to see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
================================================== ====
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
================================================== ====
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== ====

Jul 6 '07 #4
Hi Cezary,
Thanks for your detailed feedback.
test-uni.c is in UTF-16 format while test-ansi.c is CP 932. Maybe
test-uni.c is
converted to ansi by your news client program - actually I have no 936
texts under my
hand. I have only Japanese and Chinese Traditional ones. I have attached
zipped files
and snapshot of contents - Japanese speaking people can recognize it.
I did not change the program. It seemed that the developer just meant that
it was more like CP 936, not real.

Anyway, I have submitted a product issue to the development team. I will
track the issue status. If there is any update, I will post it here.

Please feel free to let me know if you have any other questions or
concerns. Thanks again for your kind feedback.

Best regards,
Charles Wang
Microsoft Online Community Support
================================================== ===
Get notification to my posts through email? Please refer to:
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications

If you are using Outlook Express, please make sure you clear the check box
"Tools/Options/Read: Get 300 headers at a time" to see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
================================================== ====
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
================================================== ====
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== ====

Jul 16 '07 #5
Hi Cezary,
It is confirmed that the 1st floating-point literals has been fixed in the
next release Orcas (VC9.0).
For the left issues, the product team has accepted them as product issues
and I believe that they will try to fix them in future.

Best regards,
Charles Wang
Microsoft Online Community Support
================================================== ===
Get notification to my posts through email? Please refer to:
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications

If you are using Outlook Express, please make sure you clear the check box
"Tools/Options/Read: Get 300 headers at a time" to see your reply promptly.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
================================================== ====
When responding to posts, please "Reply to Group" via
your newsreader so that others may learn and benefit
from this issue.
================================================== ====
This posting is provided "AS IS" with no warranties, and confers no rights.
================================================== ====



Jul 24 '07 #6
Hello,
It is confirmed that the 1st floating-point literals has been fixed in the
next release Orcas (VC9.0).
Thank you. I belive the world will be better when next programmers will not waste
time with the question ,,why this does not work?'' in mind.
For the left issues, the product team has accepted them as product issues
and I believe that they will try to fix them in future.
OK - so I am waiting patiently.

-- best regards

Cezary Noweta
Jul 25 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steve Bright | last post by:
In an ASP page, I am using the FileSystemObject OpenTextFile method to initiate a TextStream object. In some files I have long lines and it appears that these are being truncated to 2048...
1
by: hharry | last post by:
Hello All, I am attempting a bulk load of fixed position flat file data via bcp and I have noticed that I get a Right Truncation error when trying to load a row where the last column value is...
33
by: selowitch | last post by:
I've been searching in vain for a way to present typographically correct fractions (not resorting to <sup> and <sub> tags) but have been frustrated by the fact that the glyphs for one-half,...
10
by: joel.brewster | last post by:
We have a VB6 application using ADO version 2.5 and I am receiving a " CLI0109E String data right truncation. SQLSTATE=22001" error when I execute the rs.UpdateBatch method. I have determined...
2
by: Mori | last post by:
Hi, Can someone supply a code example of displaying a string with a fractional part, say 5 and 7 16ths. I cannot find an example of how to use the Encoding object (if that is what you use). ...
0
by: Galal | last post by:
Does DB2 Net Search Extender support right truncation, left truncation in Arabic, left truncation in English, or right truncation in Arabic?
2
by: coolnoff | last post by:
I have a dts which creates a table which is utilized on my local intranet. The DTS runs without error and the table is created/populated/transfered to the appropriate db. Then it appears that...
4
by: Bob | last post by:
Hi All, Was wondering if in C# there is an elegant way of displaying and or calculating fractions. The case: we have an app that measures/slices dices etc and all our internal measures and...
1
by: Semajthewise | last post by:
Here it is cleaned up a little more. Here's what this code does. It will take 2 fractions and add, subtract, multiply, or divide them. The user enters the fractions to be calculated into two...
5
by: gubbachchi | last post by:
Hi all, How to convert the fractions into decimals and vice versa in php. I have a form, where the user will enter fractions in the text boxes such as "1 1/2", "1 1/4" and so on. I need to store...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.