Here you can find the source of doubleToScale(double val)
Parameter | Description |
---|---|
val | the value from -2.0 to +1.999... |
public static int doubleToScale(double val)
//package com.java2s; /* ElmGen - DSP Development Tool * Copyright (C)2011 - Andrew Kilpatrick. Modified by Gary Worsham 2013 - 2014. Look for GSW in code. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * /* w w w . jav a 2s . co m*/ */ public class Main { /** * Converts a double to a 24 bit register value. Valid range is -2.0 to +1.999... * * @param val the value from -2.0 to +1.999... * @return the register value from -0x800000 to 0x7fffff */ public static int doubleToScale(double val) { int temp = (int) (val * (double) 0x400000); if (temp > 0x7fffff) { temp = 0x7fffff; } if (temp < -0x800000) { temp = -0x800000; } return temp; } }