Datatype for holding large number

359 views
Skip to first unread message

needi...@gmail.com

unread,
Sep 16, 2014, 8:02:15 PM9/16/14
to LR-Loa...@googlegroups.com
 Hello,

 

 I need to increment a parameter value by 1. This parameter value has 16 digits (ex:1234567890123456). When I use INT or LONG data types for this variable, it is working as expected only when the value has less than 10 digits (ex: 12345678).

But it’s not working as expected when the value exceeds 10 digits. The output is shown in red below. Could you please let me know how to fix this? Your help is very much appreciated.

 

Code:

int i;    
lr_save_string("1234567890123456", "id");
i = atoi(lr_eval_string("{id}"));    
i += 1;    

lr_save_int(i, “id");
lr_output_message("Value is: %s", lr_eval_string("{id}"));

 

Output:

Starting iteration 1.

Starting action Action.

Action.c(12): Value is: -2147483648

Ending action Action.

Ending iteration 1.

André Luyer

unread,
Sep 17, 2014, 3:30:18 AM9/17/14
to LR-Loa...@googlegroups.com
Short answer: use double.

A 16 digit decimal number can be stored in 16/log10(2) = 53 bits.
An int or long are 32 bits in size and therefore too small.
The 64-bit type 'long long' is not supported in Vugen.
A double has an accuracy of 52 bits, a bit short but probably ok in your case (when first digit < 5).

Alternatives:
- split the number up in 2 integers of max 9 digits.
- handle as string and calculate character (digit) by character in the same way you learned at school... (In C a character is a 8 bit number.)

André

yathish kumar

unread,
Sep 17, 2014, 8:15:16 AM9/17/14
to LR-Loa...@googlegroups.com
All, 

Here we have some small work around for this, this custom code might helpful in this kind of situation. 

Note - below code does not to handle if last value is 9, still have to rewrite the code if the last value is 9 but it will work fine from the value 0 to 8 at last #. If this approach is fine, then we can rewrite the same code to handle each position.

    int i;  
    char val[200] ={'\0'};
    char num;
        
lr_save_string("1234567890123451", "id");
strcpy (val, lr_eval_string("{id}"));
lr_output_message("value = %s", val);
= strlen(val) - 1;
lr_output_message("= %d", i);
num = val[i];
lr_output_message("num = %c", num);
num = num  + 1;
lr_output_message("num = %c", num);
val[i] = num;
lr_output_message("Incremented value = %s", val);

Output value - 
Action.c(12): value = 1234567890123451
Action.c(14): i = 15
Action.c(16): num = 1
Action.c(18): num = 2
Action.c(20): Incremented value = 1234567890123452


Type specifiers Range as follows , i think such a larger value does not fit into any of the below type specifiers, so we have to go for strip operations.

Type Size Range
unsigned char 8 bits 0 to 255
char 8 bits -128 to 127
unsigned int 16 bits 0 to 65,535
short int 16 bits -32,768 to 32,767
int 16 bits -32,768 to 32,767
unsigned long 32 bits 0 to 4,294,967,295
long 32 bits -2,147,483,648 to 2,147,483,647
long long32 bits-2,147,483,648 to 2,147,483,647. May be larger on some platforms and applications, but we advise not to base scripts on larger values.
unsigned long long32 bits0 to 4,294,967,295 . May be larger on some platforms and applications, but we advise not to base scripts on larger values.
float 32 bits 1.17549435 * (10^-38) to
3.40282347 * (10^+38)
double 64 bits 2.2250738585072014 * (10^-308) to 1.7976931348623157 * (10^+308)
long double 80 bits 3.4 * (10^-4932) to 1.1 * (10^4932)

Thanks,
Yathish

--
You received this message because you are subscribed to the Google Groups "LoadRunner" group.
To unsubscribe from this group and stop receiving emails from it, send an email to LR-LoadRunne...@googlegroups.com.
To post to this group, send email to LR-Loa...@googlegroups.com.
Visit this group at http://groups.google.com/group/LR-LoadRunner.
For more options, visit https://groups.google.com/d/optout.

Franklin Inbaraj

unread,
Sep 17, 2014, 9:32:11 AM9/17/14
to lr-loadrunner
the other way is -

Select the parameter type as unique number, set the starting number as xxxx (in your case 1234567890123456) and update value as needed like every occurrence / iteration etc.

Thanks
Franklin Inbaraj
--
Regards,
Franklin Inbaraj

André Luyer

unread,
Sep 17, 2014, 10:21:52 AM9/17/14
to LR-Loa...@googlegroups.com
This code will increment an any size number, including "last value is 9":

char *ptr, *id;
lr_save_string("12345678901234519999999", "id");

id = lr_eval_string("0{id}"); // assuming id contains only digits
ptr = id + strlen(id) - 1;
lr_output_message("value = %s", id + 1);
while (++*ptr > '9') *ptr-- = '0';
lr_output_message("Incremented value = %s", id[0] == '0' ? id + 1: id);

André

Pradhyumna Gupta

unread,
Sep 17, 2014, 1:07:26 PM9/17/14
to LR-Loa...@googlegroups.com

Or hard code the 1st 8 digits as "10000000" and follow it up with a "unique number" parameter of 8 digits. Append the hard coded value manually as needed.

The above works for a single user. For multiple users just create a vuid parameter and adjust the length of the unique number parameter accordingly.

On Sep 17, 2014 7:45 PM, "Pradhyumna Gupta" <pradhyum...@gmail.com> wrote:

Unique number parameter might not support 16 digit numbers.

Instead use 2 "unique number" parameters and append each by 1.
Just need to be aware of the values used after every test so that the parameter value can be adjusted for the next run.

Pradhyumna Gupta

unread,
Sep 17, 2014, 1:07:26 PM9/17/14
to LR-Loa...@googlegroups.com

Unique number parameter might not support 16 digit numbers.

Instead use 2 "unique number" parameters and append each by 1.
Just need to be aware of the values used after every test so that the parameter value can be adjusted for the next run.

On Sep 17, 2014 7:02 PM, "Franklin Inbaraj" <frankli...@gmail.com> wrote:

needi...@gmail.com

unread,
Sep 17, 2014, 11:56:20 PM9/17/14
to LR-Loa...@googlegroups.com
Thank you, Andre.

How can I hold the incremented value in a parameter? I appreciate your help.

André Luyer

unread,
Sep 19, 2014, 1:32:33 PM9/19/14
to LR-Loa...@googlegroups.com
Use lr_save_string.
Didn't you attend any HP training?

André

Vignesh Gokul

unread,
Apr 22, 2015, 9:24:50 AM4/22/15
to LR-Loa...@googlegroups.com
Hi all,
could you please guide  me how to parameterize the 19 digit value in load runner.....because LR does not allow digits greater than 10 to be parameterized

varun yadav

unread,
Apr 23, 2015, 9:17:49 AM4/23/15
to LR-Loa...@googlegroups.com

You can use file type parameter from parameter list window and put the 16 or what ever digits in the value to the column. And then use this parameter name in your script.

Thanks
Varun

--
You received this message because you are subscribed to the Google Groups "LoadRunner" group.
To unsubscribe from this group and stop receiving emails from it, send an email to LR-LoadRunne...@googlegroups.com.
To post to this group, send email to LR-Loa...@googlegroups.com.
Visit this group at http://groups.google.com/group/LR-LoadRunner.
Reply all
Reply to author
Forward
0 new messages