473,386 Members | 1,753 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,386 software developers and data experts.

__int64 convert to int

Kio
Hi,

For example:

1 __int64 fib4(__int64 n)
2 {
3 if ((n==1) || (n==2)) return 1;
4 else return (fib(n-1)+fib(n-2));
5 }

How to avoid conversion to int in line 4 ??

Thx Kio
Feb 27 '06 #1
4 7769
Kio wrote:
For example:

1 __int64 fib4(__int64 n)
2 {
3 if ((n==1) || (n==2)) return 1;
4 else return (fib(n-1)+fib(n-2));
5 }

How to avoid conversion to int in line 4 ??


Hard to tell: '__int64' is not a standard type and the rules set
up for the type are thus environment specific. You should ask this
question in a forum devoted to the specific environment you are
using.

BTW, it is a pretty bad idea to compute Fibonacci numbers using a
recursive approach in C++. The compiler will not optimize the call
to reuse results computed before as is usual for functional
programming languages (or even the C++ compiler when computing the
value using template meta programming techniques). A simple
iterative approach is much faster.
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<http://www.eai-systems.com> - Efficient Artificial Intelligence
Feb 27 '06 #2
Kio
Hard to tell: '__int64' is not a standard type and the rules set
up for the type are thus environment specific. You should ask this
question in a forum devoted to the specific environment you are
using.

BTW, it is a pretty bad idea to compute Fibonacci numbers using a
recursive approach in C++. The compiler will not optimize the call
to reuse results computed before as is usual for functional
programming languages (or even the C++ compiler when computing the
value using template meta programming techniques). A simple
iterative approach is much faster.


I know :) I'm just testing ... Do you know maybe, which compiler would not
convert it ??
Feb 27 '06 #3
>I know :) I'm just testing ... Do you know maybe, which compiler would not
convert it ??


That's not in the C++ standard, so far I only seen that as
intrinsic/extension in the Microsoft Visual C++ .. I assume that's
where you using it, so most likely the answer is 'no'. I can write you
__int64 class which won't but what's the point? :)

Feb 27 '06 #4

Dietmar Kuehl wrote:
Kio wrote:
For example:

1 __int64 fib4(__int64 n)
2 {
3 if ((n==1) || (n==2)) return 1;
4 else return (fib(n-1)+fib(n-2));
5 }

How to avoid conversion to int in line 4 ??


Hard to tell: '__int64' is not a standard type and the rules set
up for the type are thus environment specific. You should ask this
question in a forum devoted to the specific environment you are
using.


A fair guess would be

if ( __int64(0) < n && n < __int64(3) ) { /*...*/ }

which assumes an operator<(__int64,__int64) and a
__int64::__int64(int),
both of which seem reasonable. If you consider that
environment-specific,
just add template<typename T> and replace __int64 with T ;-)

Michiel.

Feb 27 '06 #5

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

Similar topics

2
by: Matt Whelan | last post by:
Supposedly, recent versions of SWIG can be made to work with MS VC++'s non-standard integer data types. According to a recent SWIG ChangeLog entry: %apply long long { __int64 }; should make...
8
by: Tim Clacy | last post by:
How is a 64 bit type defined in strict C++? It seems C has support for 'long long' since C99, but not so for C++? Looking through one compiler vendor's standard library headers has clouded the...
3
by: JR | last post by:
Take a look at TestStruct1 and TestStruct2. Clearly, the D2 part of the union is MUCH larger than the D1 portion. I would expect sizeof(TestStruct1)==sizeof(TestStruct2) but that is not the case...
1
by: Jesse Hose | last post by:
I get odd behavior in the debugger with the following code. The output of the program itself is correct, but when I add the g_bad_int64_max and g_bad_int64_min to the watch window they show values...
8
by: hurry | last post by:
hi, I am writing a c program in VC++ 6. I have 2 files with 3 functions. file-1 having two functions "a" and "c" file-2 having a single function "b" with function "a" as main() , "a"...
4
by: kgpsoftware | last post by:
Hi folks, I have a DLL which contains functions that return __int64 values, but I can't get Visual C to read the return value correctly. I am using the 2003 version. Here is the declare: ...
5
by: Jeff Bean | last post by:
I need to compute a 64 bit file offset which will get passed to the _lseeki64 function. The inputs to the offset calculation are all unsigned shorts or unsigned longs. For example: unsigned...
21
by: Angus | last post by:
I need to convert a double to a 64 bit integer. I am using __int64 but could of course use a more portable type. To perform the correct casts: double d = 3.3; __int64 i64; i64 =...
29
by: Kenzogio | last post by:
Hi, I have a struct "allmsg" and him member : unsigned char card_number; //16 allmsg.card_number
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.