Click here to Skip to main content
15,887,361 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: MFC Picture Control image size. Pin
Richard MacCutchan18-Jul-19 4:03
mveRichard MacCutchan18-Jul-19 4:03 
QuestionAlgorithm Problem(C++ solution) Pin
nirvikprantor12-Jul-19 5:05
nirvikprantor12-Jul-19 5:05 
AnswerRe: Algorithm Problem(C++ solution) PinPopular
OriginalGriff12-Jul-19 5:10
mveOriginalGriff12-Jul-19 5:10 
GeneralRe: Algorithm Problem(C++ solution) Pin
Joe Woodbury12-Jul-19 10:02
professionalJoe Woodbury12-Jul-19 10:02 
AnswerRe: Algorithm Problem(C++ solution) Pin
Stefan_Lang15-Jul-19 2:05
Stefan_Lang15-Jul-19 2:05 
AnswerRe: Algorithm Problem(C++ solution) Pin
Gerry Schmitz15-Jul-19 8:14
mveGerry Schmitz15-Jul-19 8:14 
QuestionOverflow check on integer multiplication in C ? Pin
Hans9999-Jul-19 2:01
Hans9999-Jul-19 2:01 
AnswerRe: Overflow check on integer multiplication in C ? Pin
Daniel Pfeffer9-Jul-19 3:10
professionalDaniel Pfeffer9-Jul-19 3:10 
One way would be to perform the multiplication as a double-precision operation, and then examine the high word. For unsigned values (in pseudocode):
// HI_HALF - returns the upper N/2 bits of an N-bit integer
// LO_HALF - returns the lower N/2 bits of an N-bit integer
// MAKE_DIGIT - combines two N/2-bit values to make an N-bit integer

// multiply a DIGIT a by a DIGIT b, returning a two-DIGIT result
// a, b must be unsigned

DIGIT alow = LO_HALF(a)
DIGIT ahigh = HI_HALF(a)
DIGIT blow = LO_HALF(b)
DIGIT bhigh = HI_HALF(b)
DIGIT carry
DIGIT accumulator
DIGIT result[4]

accumulator = alow * blow
carry = HI_HALF(accumulator)
result[0] = LO_HALF(accumulator)

accumulator = alow * bhigh + carry
result[1] = LO_HALF(accumulator)
result[2] = HI_HALF(accumulator)

accumulator = ahigh * blow + result[1]
result[1] = LO_HALF(accumulator)
carry = HI_HALF(accumulator)

accumulator = ahigh * bhigh + result[2] + carry
result[2] = LO_HALF(accumulator)
result[3] = HI_HALF(accumulator)

// combine result[3] and result[2] into 1 DIGIT
// combine result[1] and result[0] into 1 DIGIT
return MAKE_DIGIT(result[3], result[2]), MAKE_DIGIT(result[1], result[0])

Note that many optimizations may be performed on the above code; it is laid out like this for easy comprehension.

For the operation a * b, if the high digit is non-zero, the result has overflowed
For the operation a * b / c, if the high DIGIT of (a * b) >= c, then the entire operation will overflow.

Signed values are left as an exercise for the student.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.

AnswerRe: Overflow check on integer multiplication in C ? Pin
Joe Woodbury9-Jul-19 7:41
professionalJoe Woodbury9-Jul-19 7:41 
AnswerRe: Overflow check on integer multiplication in C ? Pin
leon de boer10-Jul-19 3:35
leon de boer10-Jul-19 3:35 
GeneralRe: Overflow check on integer multiplication in C ? Pin
CPallini10-Jul-19 4:57
mveCPallini10-Jul-19 4:57 
SuggestionI have created a Wrapper but while calling a function from C# its moving to my Lib file and giving below error andy solution? Pin
Member 143147593-Jul-19 22:14
Member 143147593-Jul-19 22:14 
GeneralRe: I have created a Wrapper but while calling a function from C# its moving to my Lib file and giving below error andy solution? Pin
leon de boer4-Jul-19 2:39
leon de boer4-Jul-19 2:39 
Question"crosslinking " - different architecture libraries - is is possible? Pin
Vaclav_1-Jul-19 10:54
Vaclav_1-Jul-19 10:54 
AnswerRe: "crosslinking " - different architecture libraries - is is possible? Pin
Richard MacCutchan1-Jul-19 20:56
mveRichard MacCutchan1-Jul-19 20:56 
AnswerRe: "crosslinking " - different architecture libraries - is is possible? Pin
leon de boer2-Jul-19 5:03
leon de boer2-Jul-19 5:03 
QuestionCreated .Dll from and .ocx using C++/CLI but interop is not loading in C# Pin
Member 143147591-Jul-19 3:16
Member 143147591-Jul-19 3:16 
QuestionReturn From DoModal with RadioButton Pin
ForNow30-Jun-19 4:50
ForNow30-Jun-19 4:50 
AnswerRe: Return From DoModal with RadioButton Pin
Victor Nijegorodov30-Jun-19 6:43
Victor Nijegorodov30-Jun-19 6:43 
AnswerRe: Return From DoModal with RadioButton Pin
Randor 30-Jun-19 7:13
professional Randor 30-Jun-19 7:13 
GeneralRe: Return From DoModal with RadioButton Pin
ForNow30-Jun-19 7:53
ForNow30-Jun-19 7:53 
GeneralRe: Return From DoModal with RadioButton Pin
Randor 30-Jun-19 8:08
professional Randor 30-Jun-19 8:08 
GeneralRe: Return From DoModal with RadioButton Pin
ForNow30-Jun-19 9:43
ForNow30-Jun-19 9:43 
PraiseRe: Return From DoModal with RadioButton Pin
Randor 30-Jun-19 14:22
professional Randor 30-Jun-19 14:22 
GeneralRe: Return From DoModal with RadioButton Pin
ForNow30-Jun-19 16:24
ForNow30-Jun-19 16:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.