5 ms·
What is a case where floating-point addition is more complicated than a string concatenation? Are you referring to some obscure architecture?
by nmilo 5y ago
What is a case where floating-point addition is more complicated than a string concatenation? Are you referring to some obscure architecture?
- messe 5y agoOne example would be an architecture on which hardware floating point is not implemented, and has to be emulated in software. This isn't uncommon in embedded, many ARM Cortex-M cores are like this AFAIK.
- nmilo 5y agoThere's a pretty big difference between doing dynamic memory allocation for string concatenation on ALL systems, and doing software addition on some embedded processors. Even on your embedded system, floating point addition is simpler than string concatenation.
- messe 5y agoI don't know, I'd argue that in the simplest cases—a bump allocator followed by a memcpy—string concatenation can be significantly simpler.
- stephc_int13 5y agoIn the worst case, and this is pretty rare these days, yes, adding two floats is a function call, but without memory allocation. Integer division or multiplication of long (64bits) can also force the compiler to inline a bit more code or even to call a function on older architecture, hardware division was not a given on ARM before ARMv6 I think, so for example on the Gameboy Advance or even the Nintendo DSi you had to be careful with division etc. But again, this will only slow down your code if you're not careful, not generating memory leaks silently in the background.
- otabdeveloper4 5y agoWhy 'memory leaks'? Presumably, destructors will be automatically called one way or another. In the simplest case, you can just store all strings on the stack.
- mst 5y agoWhen I was writing arm26 (i.e. arm2) assembly for the Archimedes everybody passed around a block of ASM that did division since the processor had a whole 16 instructions and integer division wasn't one of them. Things are less primitive these days but the memory still brings a smile to my face.