Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Sunday, November 8, 2026
About Us
Magazine
Open Source
CVS
Services
Index  »  Projects  »  libcfg+  »  Bug list  »  Bug #39

Viewing Bug Advanced Details [ Jump to Bugnotes ] [ Bug History ] [ Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0000039 library core minor always 2003-02-24 23:10 2003-08-20 13:33
 
Reporter rajo View Status public  
Assigned To
Priority normal Resolution open Platform
Status feedback Duplicate ID OS
Projection none Version
ETA none Product Version current from CVS
  Product Build
  Votes 1
 
Summary Integers cannot be initialized in float-like style
Description Integers, long integers and similar signed/unsigned datatypes cannot be initialized in float-like style. Float like style is something like 10e23, 1.6e9 and so on.
Steps To Reproduce Create integer option. Try to initialize with --integer=10e23 on command line.
Additional Information / Solution Parsing sequence:

1. Fetch string.
2. Try to convert (normal conversion).
3. If OK, go [6].
4. If failed try to conver with float conversion.
5. If OK go [8].
6. Return with CFG_ERR_BADNUMBER.
7. If there are decimal numbers return with CFG_ERR_BADNUMBER.
8. Check range and do rest of the stuff in old way.
Attached Files

Bug Notes
nepto
2003-02-25 13:48

I started with this issue implementation and come to one problem. I do not know how to detect if double/float value has numbers beyond the decimal point. This is current part of source:

<code>
if (double_val - floor(double_val) != 0.0)
return CFG_ERROR_BADNUMBER;

if (type == CFG_ULONG) {
ulong_val = (unsigned long) double_val;
} else {
long_val = (long) double_val;
}
</code>

However, the code above does the job and perfectly work. The only problem is, that there is floor() function used. If you want to use floor() or another function from math.h, you have to link your application or library with -lm switch, which forces linking against mathematical library (libm).

Basically, I want to get rid of mathematical library usage. It seems to be contraproductive to link whole stuff against math library due to only one call. Therefor we need to discover other way how to detect if there are numbers beyond decimal point in double number (double_val). Maybe with some type conversion and/or similar approach without math library usage. Ideas and comments are welcome and appreciated.
 
nepto
2003-02-28 03:11

OK, I fixed the issue. Current code looks like this and seems to work OK:

<code>
if (type == CFG_ULONG) {
ulong_val = (unsigned long) double_val;
if (double_val - (double) ulong_val != 0.0)
return CFG_ERROR_BADNUMBER;
} else {
long_val = (long) double_val;
if (double_val - (double) long_val != 0.0)
return CFG_ERROR_BADNUMBER;
}
</code>

However, we also need to determine error codes to return. There are two relevant:

CFG_ERR_BADNUMBER - cannot convert number to appropriate type
CFG_ERR_OVERFLOW - number conversion overflow

What to return when initializing integer in float-like style and number have decimal characters? (for example: --int=12e-2)

What to return when initializing integer in float-like style, number does not have decimal characters, but it is very big (as big as it cannot be converted even to double)? (for example: --int=12e100000000 <-- very big exponent)

We have to solve questions above.
 
rajo
2003-02-28 04:49

- -int=12e-2 returns CFG_ERR_BADNUMBER because number is not integer
--int=12e100000000 returns CFG_ERR_OVERFLOW because number is to big (ofcourse for all default data types. ;)
 
nepto
2003-08-19 12:40

The still persisting problem is, that this behaviour is not completelly conformed.

GOOD:

ondrej@Apolon:~/prog/libcfg+/src$ ./test --int=12e-2
***** argument '12e-2' for option 'int' could not be converted to appropriate numeric type at position 2 on command line
***** cmdline error -5 at 1: option could not be converted to appropriate numeric type
***** opt = 'int', arg = '12e-2', idx = 1, argv[idx] = '--int=12e-2'

BAD:

ondrej@Apolon:~/prog/libcfg+/src$ ./test --int=12e100000000
***** argument '12e100000000' for option 'int' could not be converted to appropriate numeric type at position 2 on command line
***** cmdline error -5 at 1: option could not be converted to appropriate numeric type
***** opt = 'int', arg = '12e100000000', idx = 1, argv[idx] = '--int=12e100000000'

Both returns the same error code (-5), what is CFG_ERR_BADNUMBER.
 
nepto
2003-08-20 13:33

This was fixed in shared.c, revision 1.34.

However there is still this problem:

If too big decimal number occurs, CFG_ERR_OVERFLOW is returned, because we do not have any solution how to detect decimal numbers for very big numbers. It this OK?
 

Bug History
Date Modified Username Field Change
2003-02-24 23:10 nepto New Bug
2003-02-24 23:11 nepto summary integers canot be initilized in float-like style => Integers cannot be initialized in float-like style
2003-02-25 09:11 nepto reporter_id nepto => rajo
2003-02-25 13:48 nepto Bugnote Added: 0000055
2003-02-25 13:48 nepto status new => feedback
2003-02-28 03:11 nepto Bugnote Added: 0000058
2003-02-28 04:49 rajo Bugnote Added: 0000059
2003-08-19 12:40 nepto Bugnote Added: 0000384
2003-08-20 13:33 nepto Bugnote Added: 0000386

Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top · Feedback form · Application form
Report bug on PLATON.SK website · Terms of use · Privacy policy