Monday, December 29, 2014

Disable CPU cores in Linux

WARNING: You should close all applications before you execute these commands, because otherwise your system might lock-up.

WARNING: Please close all applications before continuing.

You can conserve energy, reduce heat, and very indirectly lengthen your computer's longevity, by turning off some CPU cores.

For example:

To turn off CPU #3:

echo 0 | sudo tee /sys/devices/system/cpu/cpu3/online

To turn off CPU #4:

echo 0 | sudo tee /sys/devices/system/cpu/cpu4/online

To turn off CPU #5:

echo 0 | sudo tee /sys/devices/system/cpu/cpu5/online

And, et cetera.

To turn on CPU #3:

echo 1 | sudo tee /sys/devices/system/cpu/cpu3/online

To turn on CPU #4:

echo 1 | sudo tee /sys/devices/system/cpu/cpu4/online

And, et cetera.

Monday, December 1, 2014

float, double, long double - max values in hexadecimal

It is trivial, but I could not find an easy reference. Here is one, after having found it:

float (32-bit):
0X1.FFFFFEP+127F

double (64-bit):
0X1.FFFFFFFFFFFFFP+1023

long double (128-bit):
0XF.FFFFFFFFFFFFFFFP+16380L

Don't forget the letter 'L' for 128-bit floating-point value! (Otherwise, the literal value will be truncanted into 64-bit float, and that would be a bug)

Test:

#include<cstdio>
#include<cfloat>
int main(){
printf("0x20-bit %A\n0x40-bit %A\n0x80-bit %LA\n",FLT_MAX,DBL_MAX,LDBL_MAX);
return 0;}