2010年3月25日木曜日

2010年3月17日水曜日

boost unitsがおもしろい2

でradianとdegreeの変換

   boost::units::quantity theta=3.14159*boost::units::si::radians;
    boost::units::quantity deg=180.0*boost::units::degree::degrees;

    std::cout << "radian = " << theta << std::endl;
    std::cout << "degree = " << deg << std::endl;

    std::cout << std::endl;

    std::cout << "conversion " << std::endl;
    std::cout << "3.14159 radian = " << boost::units::quantity(theta)<< std::endl;
    std::cout << "180 degree = " << boost::units::quantity(deg) << std::endl;


出力は
radian = 3.14159 rad
degree = 180 deg

conversion
3.14159 radian = 180 deg
180 degree = 3.14159 rad

しかしコンパイルに時間かかるな。

boost unitsがおもしろい

こちらを見て 角度のradian, degreeの変換を調べようとしたらひっかかてしまった。

F  = 2 N
dx = 2 m
E  = 4 J

V   = (12.5,0) V
I   = (3,4) A
Z   = (1.5,-2) Ohm
I*Z = (12.5,0) V
I*Z == V? true

ソースはこちら

boostでπ(M_PI)

math.hぢゃあなくてやりたいとすると。
Math Toolkitを使えば、
ライブラリリストからMath->Statistical Distributions->Internal Details and Tools (Experimental)->Numeric Constants

#include <boost/math/constants/constants.hpp>
pi=boost::math::constants::pi<double>()

1)まあ Experimentalと書いてあるがいいとしよう。
2)タイトル(Math Toolkit)がなかなかMathライブラリの中に見つからなかったぞ。統一してほしいぞ。

2010年3月10日水曜日

BOOST_CHECK_CLOSEのtolerance_srcは%!

  v=1.0;
  BOOST_CHECK_CLOSE( v, 1.3, 20.0);
  BOOST_CHECK_CLOSE( v, 1.3, 30.0);
  BOOST_CHECK_CLOSE( v, 1.3, 40.0);

test.cpp(64): error in "interpolate": difference{23.0769%} between v{1} and 1.3{1.3} exceeds 20%
test.cpp(65): error in "interpolate": difference{30%} between v{1} and 1.3{1.3} exceeds 30%

2010年3月2日火曜日

cmakeでGUI @WIN32

cmake2.8でCUIからcmake GUIを起動するには、
たとえばVC++のprojects,solutionを1つしたのbuildに入れるとすると、buildでcmake-gui.exe ..とするとよい。
参照

2010年3月1日月曜日

Debian lennyをiBook G4へインストール

まずは使えんポインティングデバイスから。
/etc/sysctl.confに
# 3-button mouse emulation
# 3 ボタンマウスエミュレーション
# turn on emulation
# エミュレーション開始
/dev/mac_hid/mouse_button_emulation = 1
# Send middle mouse button signal with the F11 key
# F11 キーでマウスの中ボタン信号を送る
/dev/mac_hid/mouse_button2_keycode = 87
# Send right mouse button signal with the F12 key
# F12 キーでマウスの右ボタン信号を送る
/dev/mac_hid/mouse_button3_keycode = 88
# For different keys, use showkey to tell you what the code is.
# ほかのキーを使う場合は showkey で必要なコードがわかる
で右クリックが可能になる。

gdmでのキーボードを/etc/X11/xorg.confで変更
Section "InputDevice"
Identifier "Generic Keyboard"
Driver "kbd"
Option "XkbRules" "xorg"
Option "XkbModel" "jp106"
Option "XkbLayout" "jp"
EndSection
で軽い用途には充分。